Skip to content

Commit

Permalink
Fix SD 3.3.0 compatibility (fixes #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Belgabor committed Oct 30, 2016
1 parent 1f06f61 commit d5fcbb7
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 99 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
@@ -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
13 changes: 2 additions & 11 deletions src/main/java/mods/belgabor/bitdrawers/BitDrawers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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",
Expand All @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,26 +14,26 @@
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;
import net.minecraft.util.EnumFacing;
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);
}
Expand All @@ -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;
Expand All @@ -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<String, PlayerConfigSetting<?>> configSettings = ConfigManager.serverPlayerConfigSettings.get(player.getUniqueID());
boolean invertShift = false;
if (configSettings != null) {
PlayerConfigSetting<Boolean> setting = (PlayerConfigSetting<Boolean>) configSettings.get("invertShift");
if (setting != null) {
invertShift = setting.value;
}
}

ItemStack held = player.inventory.getCurrentItem();
if (held == null && BitDrawers.config.debugTrace) {
tileDrawers.updateCache();
Expand All @@ -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);
Expand All @@ -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);
Expand Down
60 changes: 29 additions & 31 deletions src/main/java/mods/belgabor/bitdrawers/block/BlockBitDrawers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,27 +29,26 @@
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;
import net.minecraft.util.EnumFacing;
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.
Expand Down Expand Up @@ -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;
Expand All @@ -214,11 +203,20 @@ protected void onBlockClickedAsync (World world, BlockPos pos, EntityPlayer play
if (!SecurityManager.hasAccess(player.getGameProfile(), tileDrawers))
return;

Map<String, PlayerConfigSetting<?>> configSettings = ConfigManager.serverPlayerConfigSettings.get(player.getUniqueID());
boolean invertShift = false;
if (configSettings != null) {
PlayerConfigSetting<Boolean> setting = (PlayerConfigSetting<Boolean>) 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);
Expand Down Expand Up @@ -274,15 +272,15 @@ 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
item.stackSize = 1;
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)
Expand All @@ -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);
Expand Down
Loading

0 comments on commit d5fcbb7

Please sign in to comment.