diff --git a/Changelog.md b/Changelog.md index 56c2a35..3bf788d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ # Changelog +## Version 0.32 +* [FIXED] Compatibility with Storage Drawers 3.3.0 (Belgabor/DrawersBits#5) + ## Version 0.31 * [NEW] Config option to turn the bit drawer controller off diff --git a/build.properties b/build.properties index 746fd7c..51f77e1 100644 --- a/build.properties +++ b/build.properties @@ -1,4 +1,4 @@ minecraft_version = 1.10.2 -forge_version = 12.18.1.2049 -mod_version = 0.31 +forge_version = 12.18.1.2065 +mod_version = 0.32 release_type = alpha diff --git a/src/main/java/mods/belgabor/bitdrawers/BitDrawers.java b/src/main/java/mods/belgabor/bitdrawers/BitDrawers.java index 18adc2b..51a4a3c 100644 --- a/src/main/java/mods/belgabor/bitdrawers/BitDrawers.java +++ b/src/main/java/mods/belgabor/bitdrawers/BitDrawers.java @@ -3,7 +3,6 @@ /** * Created by Belgabor on 02.06.2016. */ -import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage; import com.jaquadro.minecraft.storagedrawers.network.CountUpdateMessage; import mod.chiselsandbits.api.ChiselsAndBitsAddon; import mod.chiselsandbits.api.IChiselAndBitsAPI; @@ -13,8 +12,6 @@ import mods.belgabor.bitdrawers.core.BlockRegistry; import mods.belgabor.bitdrawers.core.CommonProxy; import mods.belgabor.bitdrawers.core.RecipeRegistry; -import mods.belgabor.bitdrawers.event.PlayerEventHandler; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; @@ -26,13 +23,13 @@ import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.relauncher.Side; -@Mod(modid = BitDrawers.MODID, version = BitDrawers.VERSION, name = BitDrawers.MODNAME, dependencies = "required-after:chiselsandbits@[11.6,);required-after:StorageDrawers@[1.10.2-3.2.4,);required-after:Chameleon") +@Mod(modid = BitDrawers.MODID, version = BitDrawers.VERSION, name = BitDrawers.MODNAME, dependencies = "required-after:chiselsandbits@[11.6,);required-after:StorageDrawers@[1.10.2-3.3.0,);required-after:Chameleon") @ChiselsAndBitsAddon public class BitDrawers implements IChiselsAndBitsAddon { public static final String MODNAME = "Drawers & Bits"; public static final String MODID = "bitdrawers"; - public static final String VERSION = "0.31"; + public static final String VERSION = "0.32"; @SidedProxy( clientSide = "mods.belgabor.bitdrawers.client.ClientProxy", @@ -56,7 +53,6 @@ public void preInit(FMLPreInitializationEvent event) network = NetworkRegistry.INSTANCE.newSimpleChannel(MODID); blocks.init(); proxy.initClient(); - network.registerMessage(BlockClickMessage.Handler.class, BlockClickMessage.class, 0, Side.SERVER); if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { network.registerMessage(CountUpdateMessage.Handler.class, CountUpdateMessage.class, 1, Side.CLIENT); @@ -66,11 +62,6 @@ public void preInit(FMLPreInitializationEvent event) } } - @EventHandler - public void init(FMLInitializationEvent event) { - //MinecraftForge.EVENT_BUS.register(new PlayerEventHandler()); - } - @EventHandler public void postInit(FMLPostInitializationEvent event) { recipes.init(); diff --git a/src/main/java/mods/belgabor/bitdrawers/block/BlockBitController.java b/src/main/java/mods/belgabor/bitdrawers/block/BlockBitController.java index b8fa84e..c410197 100644 --- a/src/main/java/mods/belgabor/bitdrawers/block/BlockBitController.java +++ b/src/main/java/mods/belgabor/bitdrawers/block/BlockBitController.java @@ -1,11 +1,10 @@ package mods.belgabor.bitdrawers.block; -import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.block.BlockController; import com.jaquadro.minecraft.storagedrawers.block.IBlockDestroyHandler; -import com.jaquadro.minecraft.storagedrawers.block.IExtendedBlockClickHandler; -import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage; -import com.jaquadro.minecraft.storagedrawers.network.BlockDestroyMessage; +import com.jaquadro.minecraft.storagedrawers.config.ConfigManager; +import com.jaquadro.minecraft.storagedrawers.config.PlayerConfigSetting; +import com.jaquadro.minecraft.storagedrawers.security.SecurityManager; import mod.chiselsandbits.api.IBitBag; import mod.chiselsandbits.api.ItemType; import mods.belgabor.bitdrawers.BitDrawers; @@ -15,6 +14,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemStack; @@ -22,19 +22,18 @@ import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraft.world.WorldServer; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; +import java.util.Map; + /** * Created by Belgabor on 24.07.2016. */ -public class BlockBitController extends BlockController implements IExtendedBlockClickHandler, IBlockDestroyHandler { +public class BlockBitController extends BlockController implements /*IExtendedBlockClickHandler,*/ IBlockDestroyHandler { public BlockBitController(String name) { super(name); } @@ -46,25 +45,25 @@ public TileBitController createNewTileEntity (World world, int meta) { public EnumFacing getDirection (IBlockAccess blockAccess, BlockPos pos) { IBlockState state = blockAccess.getBlockState(pos); - //return (tile != null) ? EnumFacing.getFront(tile.getDirection()) : EnumFacing.NORTH; EnumFacing facing = (state != null) ? state.getValue(FACING) : EnumFacing.NORTH; return (facing != null) ? facing : EnumFacing.NORTH; } - @Override public boolean removedByPlayer (IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { if (player.capabilities.isCreativeMode) { + float blockReachDistance = 0; if (world.isRemote) { - RayTraceResult ray = Minecraft.getMinecraft().objectMouseOver; + blockReachDistance = Minecraft.getMinecraft().playerController.getBlockReachDistance() + 1; + } else { + blockReachDistance = (float) ((EntityPlayerMP) player).interactionManager.getBlockReachDistance() + 1; + } - if (getDirection(world, pos) == ray.sideHit) { - onBlockClicked(world, pos, player); - if (BitDrawers.config.debugTrace) - BDLogger.info(StorageDrawers.MOD_ID, "BlockBitController.removedByPlayer with " + ray.toString()); - } else { - StorageDrawers.network.sendToServer(new BlockDestroyMessage(pos)); - } + RayTraceResult rayResult = net.minecraftforge.common.ForgeHooks.rayTraceEyes(player, blockReachDistance + 1); + if (getDirection(world, pos) == rayResult.sideHit) { + onBlockClicked(world, pos, player); + } else { + world.setBlockState(pos, net.minecraft.init.Blocks.AIR.getDefaultState(), world.isRemote ? 11 : 3); } return false; @@ -87,44 +86,31 @@ private void onBlockDestroyedAsync(World world, BlockPos pos) { @Override public void onBlockClicked (World world, BlockPos pos, EntityPlayer player) { if (world.isRemote) { - RayTraceResult ray = Minecraft.getMinecraft().objectMouseOver; - BlockPos posb = ray.getBlockPos(); - float hitX = (float)(ray.hitVec.xCoord - posb.getX()); - float hitY = (float)(ray.hitVec.yCoord - posb.getY()); - float hitZ = (float)(ray.hitVec.zCoord - posb.getZ()); - - StorageDrawers.network.sendToServer(new BlockClickMessage(pos.getX(), pos.getY(), pos.getZ(), ray.sideHit.ordinal(), hitX, hitY, hitZ, StorageDrawers.config.cache.invertShift)); - - if (BitDrawers.config.debugTrace) - BDLogger.info("BlockBitController.onBlockClicked with " + ray.toString()); - } - } - - @Override - public void onBlockClicked (final World world, final BlockPos pos, final EntityPlayer player, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final boolean invertShift) { - if (world.isRemote) return; + } + RayTraceResult ray = Minecraft.getMinecraft().objectMouseOver; + EnumFacing side = ray.sideHit; if (BitDrawers.config.debugTrace) - BDLogger.info("BlockBitController:onBlockClicked %f %f %f", hitX, hitY, hitZ); - - ((WorldServer)world).addScheduledTask(() -> BlockBitController.this.onBlockClickedAsync(world, pos, player, side, hitX, hitY, hitZ, invertShift)); - } - - protected void onBlockClickedAsync (World world, BlockPos pos, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ, boolean invertShift) { - if (BitDrawers.config.debugTrace) - BDLogger.info("IExtendedBlockClickHandler.onBlockClicked"); - - if (!player.capabilities.isCreativeMode) { - PlayerInteractEvent.LeftClickBlock event = new PlayerInteractEvent.LeftClickBlock(player, pos, side, new Vec3d(hitX, hitY, hitZ)); - MinecraftForge.EVENT_BUS.post(event); - if (event.isCanceled()) - return; - } + BDLogger.info("BlockBitController.onBlockClicked with " + ray.toString()); + TileBitController tileDrawers = (TileBitController) getTileEntitySafe(world, pos); - if (getDirection(world, pos).ordinal() != side.ordinal()) + + if (!SecurityManager.hasAccess(player.getGameProfile(), tileDrawers)) return; + if (getDirection(world, pos).ordinal() != side.ordinal()) + return; + + Map> configSettings = ConfigManager.serverPlayerConfigSettings.get(player.getUniqueID()); + boolean invertShift = false; + if (configSettings != null) { + PlayerConfigSetting setting = (PlayerConfigSetting) configSettings.get("invertShift"); + if (setting != null) { + invertShift = setting.value; + } + } + ItemStack held = player.inventory.getCurrentItem(); if (held == null && BitDrawers.config.debugTrace) { tileDrawers.updateCache(); @@ -134,7 +120,7 @@ protected void onBlockClickedAsync (World world, BlockPos pos, EntityPlayer play ItemStack item = null; if (handler instanceof IBitBag) { IBitBag bag = (IBitBag) handler; - + int retrieved = tileDrawers.fillBag(bag, player.getGameProfile()); if (retrieved > 0 && !world.isRemote) world.playSound(null, pos.getX() + .5f, pos.getY() + .5f, pos.getZ() + .5f, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, .2f, ((world.rand.nextFloat() - world.rand.nextFloat()) * .7f + 1) * 2); @@ -153,7 +139,7 @@ else if (!world.isRemote) } } - + protected void dropItemStack (World world, BlockPos pos, EntityPlayer player, ItemStack stack) { EntityItem entity = new EntityItem(world, pos.getX() + .5f, pos.getY() + .1f, pos.getZ() + .5f, stack); entity.addVelocity(-entity.motionX, -entity.motionY, -entity.motionZ); diff --git a/src/main/java/mods/belgabor/bitdrawers/block/BlockBitDrawers.java b/src/main/java/mods/belgabor/bitdrawers/block/BlockBitDrawers.java index 75c1b4b..4587947 100644 --- a/src/main/java/mods/belgabor/bitdrawers/block/BlockBitDrawers.java +++ b/src/main/java/mods/belgabor/bitdrawers/block/BlockBitDrawers.java @@ -7,6 +7,8 @@ import com.jaquadro.minecraft.storagedrawers.block.EnumCompDrawer; import com.jaquadro.minecraft.storagedrawers.block.dynamic.StatusModelData; import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers; +import com.jaquadro.minecraft.storagedrawers.config.ConfigManager; +import com.jaquadro.minecraft.storagedrawers.config.PlayerConfigSetting; import com.jaquadro.minecraft.storagedrawers.inventory.DrawerInventoryHelper; import com.jaquadro.minecraft.storagedrawers.security.SecurityManager; import mod.chiselsandbits.api.APIExceptions; @@ -27,6 +29,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.SoundEvents; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -34,20 +37,18 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import java.util.List; +import java.util.Map; /** * Created by Belgabor on 02.06.2016. @@ -178,32 +179,20 @@ public void breakBlock (World world, BlockPos pos, IBlockState state) { @Override public void onBlockClicked(World world, BlockPos pos, EntityPlayer player) { - if (world.isRemote && BitDrawers.config.debugTrace) - BDLogger.info("BlockBitDrawers:onBlockClicked"); - super.onBlockClicked(world, pos, player); - } - - @Override - public void onBlockClicked (final World world, final BlockPos pos, final EntityPlayer player, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final boolean invertShift) { - if (world.isRemote) + if (world.isRemote) { return; - - if (BitDrawers.config.debugTrace) - BDLogger.info("BlockBitDrawers:onBlockClicked %f %f %f", hitX, hitY, hitZ); - - ((WorldServer)world).addScheduledTask(() -> BlockBitDrawers.this.onBlockClickedAsync(world, pos, player, side, hitX, hitY, hitZ, invertShift)); - } + } - protected void onBlockClickedAsync (World world, BlockPos pos, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ, boolean invertShift) { if (BitDrawers.config.debugTrace) BDLogger.info("IExtendedBlockClickHandler.onBlockClicked"); - - if (!player.capabilities.isCreativeMode) { - PlayerInteractEvent.LeftClickBlock event = new PlayerInteractEvent.LeftClickBlock(player, pos, side, new Vec3d(hitX, hitY, hitZ)); - MinecraftForge.EVENT_BUS.post(event); - if (event.isCanceled()) - return; - } + + RayTraceResult rayResult = net.minecraftforge.common.ForgeHooks.rayTraceEyes(player, ((EntityPlayerMP) player).interactionManager.getBlockReachDistance() + 1); + EnumFacing side = rayResult.sideHit; + // adjust hitVec for drawers + float hitX = (float)(rayResult.hitVec.xCoord - pos.getX()); + float hitY = (float)(rayResult.hitVec.yCoord - pos.getY()); + float hitZ = (float)(rayResult.hitVec.zCoord - pos.getZ()); + TileEntityDrawers tileDrawers = getTileEntitySafe(world, pos); if (tileDrawers.getDirection() != side.ordinal()) return; @@ -214,11 +203,20 @@ protected void onBlockClickedAsync (World world, BlockPos pos, EntityPlayer play if (!SecurityManager.hasAccess(player.getGameProfile(), tileDrawers)) return; + Map> configSettings = ConfigManager.serverPlayerConfigSettings.get(player.getUniqueID()); + boolean invertShift = false; + if (configSettings != null) { + PlayerConfigSetting setting = (PlayerConfigSetting) configSettings.get("invertShift"); + if (setting != null) { + invertShift = setting.value; + } + } + int slot = getDrawerSlot(getDrawerCount(world.getBlockState(pos)), side.ordinal(), hitX, hitY, hitZ); IDrawer drawer = tileDrawers.getDrawer(slot); ItemStack item; - + ItemStack held = player.inventory.getCurrentItem(); ItemType heldType = BitDrawers.cnb_api.getItemType(held); IItemHandler handler = held==null?null:held.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); @@ -274,7 +272,7 @@ protected void onBlockClickedAsync (World world, BlockPos pos, EntityPlayer play if (item == null) return; int bitCount = item.stackSize; - + if (player.isSneaking() != invertShift) item.stackSize = 64; else @@ -282,7 +280,7 @@ protected void onBlockClickedAsync (World world, BlockPos pos, EntityPlayer play item.stackSize = Math.min(item.stackSize, drawer.getStoredItemCount() / bitCount); if (item.stackSize == 0) return; - + drawer.setStoredItemCount(drawer.getStoredItemCount() - (item.stackSize * bitCount)); } else { if (player.isSneaking() != invertShift) @@ -303,9 +301,9 @@ protected void onBlockClickedAsync (World world, BlockPos pos, EntityPlayer play else if (!world.isRemote) world.playSound(null, pos.getX() + .5f, pos.getY() + .5f, pos.getZ() + .5f, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, .2f, ((world.rand.nextFloat() - world.rand.nextFloat()) * .7f + 1) * 2); } - - } + } + protected void dropItemStack (World world, BlockPos pos, EntityPlayer player, ItemStack stack) { EntityItem entity = new EntityItem(world, pos.getX() + .5f, pos.getY() + .1f, pos.getZ() + .5f, stack); entity.addVelocity(-entity.motionX, -entity.motionY, -entity.motionZ); diff --git a/src/main/java/mods/belgabor/bitdrawers/block/tile/TileBitController.java b/src/main/java/mods/belgabor/bitdrawers/block/tile/TileBitController.java index 93ada42..e3d2dbf 100644 --- a/src/main/java/mods/belgabor/bitdrawers/block/tile/TileBitController.java +++ b/src/main/java/mods/belgabor/bitdrawers/block/tile/TileBitController.java @@ -1,5 +1,7 @@ package mods.belgabor.bitdrawers.block.tile; +import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; @@ -15,9 +17,12 @@ import mods.belgabor.bitdrawers.BitDrawers; import mods.belgabor.bitdrawers.core.BDLogger; import mods.belgabor.bitdrawers.core.BitHelper; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.world.ILockableContainer; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; @@ -26,8 +31,9 @@ /** * Created by Belgabor on 24.07.2016. */ -public class TileBitController extends TileEntityController { +public class TileBitController extends TileEntityController implements IProtectable { protected Map> drawerBitLookup = new HashMap<>(); + private String securityKey; @Override public int interactPutItemsIntoInventory (EntityPlayer player) { @@ -196,12 +202,16 @@ protected int insertChiseledBlocks(ItemStack stack, GameProfile profile) { @Override protected void resetCache() { + if (BitDrawers.config.debugTrace) + BDLogger.info("TileBitController:resetCache"); drawerBitLookup.clear(); super.resetCache(); } @Override public void updateCache() { + if (BitDrawers.config.debugTrace) + BDLogger.info("TileBitController:updateCache"); super.updateCache(); rebuildBitLookup(drawerBitLookup, drawerSlotList); } @@ -226,10 +236,10 @@ protected void rebuildBitLookup (Map> lookup, List slotRecords = lookup.get(brush.getStateID()); if (slotRecords == null) { slotRecords = new ArrayList<>(); @@ -239,6 +249,8 @@ protected void rebuildBitLookup (Map> lookup, List available = new HashMap<>(); counter.counts.forEach((blockStateID, count) -> { + if (BitDrawers.config.debugTrace) + BDLogger.info("Needed %d %d", blockStateID, count); available.put(blockStateID, 0); List records = drawerBitLookup.get(blockStateID); if (records == null) return; records.stream().forEachOrdered(slotRecord -> { + if (BitDrawers.config.debugTrace) + BDLogger.info(" Trying %d", slotRecord.slot); IDrawer drawer = getAccessibleBitDrawer(slotRecord, profile); if (drawer != null) { + if (BitDrawers.config.debugTrace) + BDLogger.info(" Drawer found: %d", slotRecord.slot); available.put(blockStateID, available.get(blockStateID) + drawer.getStoredItemCount()); } }); @@ -347,6 +372,8 @@ public ItemStack retrieveByPattern(ItemStack pattern, EntityPlayer player, boole Integer[] max = new Integer[1]; max[0] = Integer.MAX_VALUE; available.forEach((blockStateID, count) -> { + if (BitDrawers.config.debugTrace) + BDLogger.info("Available %d %d", blockStateID, count); int m = count / counter.counts.get(blockStateID); if (m == 0 && BitDrawers.config.chatty) { ItemStack desc = (new BitBrush(blockStateID)).getItemStack(1); @@ -388,6 +415,66 @@ public ItemStack retrieveByPattern(ItemStack pattern, EntityPlayer player, boole } return stack; } + + @Override + public void readFromNBT (NBTTagCompound tag) { + super.readFromNBT(tag); + + securityKey = null; + if (tag.hasKey("Sec")) + securityKey = tag.getString("Sec"); + + } + + @Override + public NBTTagCompound writeToNBT (NBTTagCompound tag) { + super.writeToNBT(tag); + + if (securityKey != null) + tag.setString("Sec", securityKey); + + return tag; + } + + @Override + public UUID getOwner() { + return null; + } + + @Override + public boolean setOwner(UUID uuid) { + return false; + } + + @Override + public ISecurityProvider getSecurityProvider() { + return StorageDrawers.securityRegistry.getProvider(securityKey); + } + + @Override + public ILockableContainer getLockableContainer() { + return null; + } + + @Override + public boolean setSecurityProvider(ISecurityProvider provider) { + if (!StorageDrawers.config.cache.enablePersonalUpgrades) + return false; + + String newKey = (provider == null) ? null : provider.getProviderID(); + if ((newKey != null && !newKey.equals(securityKey)) || (securityKey != null && !securityKey.equals(newKey))) { + securityKey = newKey; + + if (worldObj != null && !worldObj.isRemote) { + markDirty(); + + IBlockState state = worldObj.getBlockState(getPos()); + worldObj.notifyBlockUpdate(getPos(), state, state, 3); + } + } + + return true; + } protected static class BitCollectorData { protected final int count;