diff options
-rw-r--r-- | src/main/java/re/jag/parquet/MusicDiscDispenserBehavior.java | 36 | ||||
-rw-r--r-- | src/main/java/re/jag/parquet/Parquet.java | 31 |
2 files changed, 64 insertions, 3 deletions
diff --git a/src/main/java/re/jag/parquet/MusicDiscDispenserBehavior.java b/src/main/java/re/jag/parquet/MusicDiscDispenserBehavior.java new file mode 100644 index 0000000..4a64e3a --- /dev/null +++ b/src/main/java/re/jag/parquet/MusicDiscDispenserBehavior.java @@ -0,0 +1,36 @@ +package re.jag.parquet; + +import net.minecraft.block.*; +import net.minecraft.block.dispenser.FallibleItemDispenserBehavior; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPointer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.World; + +public class MusicDiscDispenserBehavior extends FallibleItemDispenserBehavior { + + protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) { + World world = pointer.getWorld(); + Direction direction = (Direction)pointer.getBlockState().get(DispenserBlock.FACING); + BlockPos block_pos = pointer.getBlockPos().offset(direction); + BlockState state = world.getBlockState(block_pos); + + if (state.isOf(Blocks.JUKEBOX)) { + JukeboxBlock block = (JukeboxBlock)state.getBlock(); + ItemStack disc_stack = stack.split(1); + + if (state.get(JukeboxBlock.HAS_RECORD)) // Remove record if present + block.onUse(state, world, block_pos, null, null, null); + + block.setRecord(world, block_pos, state, disc_stack); + world.syncWorldEvent((PlayerEntity)null, 1010, block_pos, Item.getRawId(disc_stack.getItem())); + + return stack; + } + + return super.dispenseSilently(pointer, stack); + } +} diff --git a/src/main/java/re/jag/parquet/Parquet.java b/src/main/java/re/jag/parquet/Parquet.java index e031f29..123ac23 100644 --- a/src/main/java/re/jag/parquet/Parquet.java +++ b/src/main/java/re/jag/parquet/Parquet.java @@ -1,5 +1,10 @@ package re.jag.parquet; +import net.minecraft.item.MusicDiscItem; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.Identifier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -15,6 +20,8 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.util.DyeColor; import re.jag.parquet.commands.*; +import net.minecraft.util.registry.Registry; + public class Parquet implements ModInitializer { public static final Logger LOG = LogManager.getLogger(); @@ -44,13 +51,31 @@ public class Parquet implements ModInitializer { DispenserBlock.registerBehavior(DyeItem.byColor(dye_color).asItem(), new DyeItemDispenserBehavior()); } - - + + // MusicDiscItem.MUSIC_DISCS Map is private. + MusicDiscItem[] music_discs = { + (MusicDiscItem) Items.MUSIC_DISC_13, + (MusicDiscItem) Items.MUSIC_DISC_CAT, + (MusicDiscItem) Items.MUSIC_DISC_BLOCKS, + (MusicDiscItem) Items.MUSIC_DISC_CHIRP, + (MusicDiscItem) Items.MUSIC_DISC_FAR, + (MusicDiscItem) Items.MUSIC_DISC_MALL, + (MusicDiscItem) Items.MUSIC_DISC_MELLOHI, + (MusicDiscItem) Items.MUSIC_DISC_STAL, + (MusicDiscItem) Items.MUSIC_DISC_STRAD, + (MusicDiscItem) Items.MUSIC_DISC_WARD, + (MusicDiscItem) Items.MUSIC_DISC_11, + (MusicDiscItem) Items.MUSIC_DISC_WAIT, + (MusicDiscItem) Items.MUSIC_DISC_PIGSTEP + }; + for (MusicDiscItem item : music_discs ) + DispenserBlock.registerBehavior(item, new MusicDiscDispenserBehavior()); + DispenserBlock.registerBehavior(Items.WATER_BUCKET, new WaterBucketDispenserBehavior()); DispenserBlock.registerBehavior(Items.BUCKET, new BucketDispenserBehavior()); DispenserBlock.registerBehavior(Items.GLASS_BOTTLE, new GlassBottleDispenserBehavior()); DispenserBlock.registerBehavior(Items.POTION, new PotionDispenserBehavior()); - + LOG.info("[PQ] Registered Custom Dispenser behaviors"); } |