@@ 1,23 @@
+# Jukebox Hopper mod
+
+This is a mod which allows the player to use a hopper
+to insert a record into a Jukebox in Minecraft.
+
+## Building
+
+1. Copy the directory into your [MCP](https://minecraft.gamepedia.com/Programs_and_editors/Mod_Coder_Pack) workspace.
+2. Locate method `transferItemsOut()` in `net.minecraft.tileentity`.
+3. Add the snippet below at the start of the method.
+
+Snippet:
+```java
+if(JukeboxHopperMod.canTransferRecord(this)){
+ JukeboxHopperMod.transferRecord(this);
+ return true;
+}
+```
+
+You should be able to reobfuscate/startclient.
+Tested with Minecraft 1.12, if you are using a newer version you may
+need to change a few things before it can run.
+
@@ 1,54 @@
+package ae.humaidq.minimod.jukehopper;
+import net.minecraft.block.Block;
+public class HopperUtils {
+
+ public static boolean canTransferRecord(TileEntityHopper entityHopper) {
+ return (getJukeboxFromHopper(entityHopper) != null);
+ }
+
+ public static void transferRecord(TileEntityHopper entityHopper) {
+ for (int i = 0; i < entityHopper.getSizeInventory(); ++i) {
+ if (!entityHopper.getStackInSlot(i).func_190926_b()) {
+ ItemStack itemstack = entityHopper.getStackInSlot(i).copy();
+ if (itemstack.getItem() instanceof ItemRecord) {
+ BlockJukebox.TileEntityJukebox jbe = getJukeboxFromHopper(entityHopper);
+ if (jbe != null) {
+ ItemStack decr = entityHopper.decrStackSize(i, 1);
+ BlockPos blockpos = getFacingBlockPos(entityHopper);
+ jbe.setRecord(itemstack.copy());
+ entityHopper.getWorld().setBlockState(blockpos, entityHopper.getWorld().getBlockState(blockpos).withProperty(BlockJukebox.HAS_RECORD, true), 2);
+ entityHopper.getWorld().playEvent(null, 1010, blockpos, Item.getIdFromItem(decr.getItem()));
+ decr.func_190918_g(1); // decrement
+ entityHopper.setInventorySlotContents(i, decr);
+ }
+ }
+ }
+
+ }
+ }
+
+ private static BlockPos getFacingBlockPos(TileEntityHopper entityHopper) {
+ EnumFacing enumfacing = BlockHopper.getFacing(entityHopper.getBlockMetadata());
+ int x = MathHelper.floor(entityHopper.getXPos() + (double) enumfacing.getFrontOffsetX());
+ int y = MathHelper.floor(entityHopper.getYPos() + (double) enumfacing.getFrontOffsetY());
+ int z = MathHelper.floor(entityHopper.getZPos() + (double) enumfacing.getFrontOffsetZ());
+ return new BlockPos(x, y, z);
+ }
+
+ private static BlockJukebox.TileEntityJukebox getJukeboxFromHopper(TileEntityHopper entityHopper) {
+ BlockJukebox.TileEntityJukebox jb = null;
+ BlockPos blockpos = getFacingBlockPos(entityHopper);
+ World worldIn = entityHopper.getWorld();
+ Block block = worldIn.getBlockState(blockpos).getBlock();
+ if (block.hasTileEntity()) {
+ TileEntity tileentity = worldIn.getTileEntity(blockpos);
+ if (tileentity instanceof BlockJukebox.TileEntityJukebox) {
+ IBlockState blockstate = worldIn.getBlockState(blockpos);
+ if (!blockstate.getValue(BlockJukebox.HAS_RECORD)) {
+ jb = ((BlockJukebox.TileEntityJukebox) tileentity);
+ }
+ }
+ }
+ return jb;
+ }
+}