aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-10-18 20:42:29 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-10-18 20:42:29 +0200
commitd461f261d9dac104ad93b5baca6a353780db0114 (patch)
tree15de1f6e32210223ca2a28a1d6abc3debe419a26 /src/main
parent8f06ef25667e149d685c7ff9e696ddf7e61e5ed9 (diff)
downloadparquet-d461f261d9dac104ad93b5baca6a353780db0114.tar.gz
MusicDiscs can be placed in JukeBox by Dispenser
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/re/jag/parquet/MusicDiscDispenserBehavior.java36
-rw-r--r--src/main/java/re/jag/parquet/Parquet.java31
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");
}