diff --git a/src/main/java/tschipp/carryon/CarryOn.java b/src/main/java/tschipp/carryon/CarryOn.java index 8c1f25d..66c08da 100644 --- a/src/main/java/tschipp/carryon/CarryOn.java +++ b/src/main/java/tschipp/carryon/CarryOn.java @@ -12,8 +12,10 @@ import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import tschipp.carryon.common.CommonProxy; +import tschipp.carryon.common.command.CommandCarryOn; @EventBusSubscriber @Mod(modid = CarryOn.MODID, name = CarryOn.NAME, version = CarryOn.VERSION, guiFactory = "tschipp.carryon.client.gui.GuiFactoryCarryOn", updateJSON = CarryOn.UPDATE_JSON) @@ -27,7 +29,7 @@ public class CarryOn { public static CarryOn instance; public static final String MODID = "carryon"; - public static final String VERSION = "1.3"; + public static final String VERSION = "1.4"; public static final String NAME = "Carry On"; public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/"; public static final Logger LOGGER = LogManager.getFormatterLogger("CarryOn"); @@ -48,5 +50,11 @@ public class CarryOn { public void postInit(FMLPostInitializationEvent event) { CarryOn.proxy.postInit(event); } + + @EventHandler + public void serverLoad(FMLServerStartingEvent event) + { + event.registerServerCommand(new CommandCarryOn()); + } } \ No newline at end of file diff --git a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java index c48580d..a215ba2 100644 --- a/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java +++ b/src/main/java/tschipp/carryon/client/event/RenderEntityEvents.java @@ -1,29 +1,23 @@ package tschipp.carryon.client.event; import java.lang.reflect.Field; - -import org.lwjgl.opengl.GL11; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.model.ModelPlayer; -import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.client.renderer.entity.RenderPlayer; -import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.client.event.GuiOpenEvent; @@ -46,7 +40,7 @@ public class RenderEntityEvents */ @SideOnly(Side.CLIENT) @SubscribeEvent - public void onScroll(MouseEvent event) + public void onScroll(MouseEvent event) throws IllegalArgumentException, IllegalAccessException { if (event.getDwheel() > 0 || event.getDwheel() < 0) { @@ -57,6 +51,7 @@ public class RenderEntityEvents event.setCanceled(true); } } + } /* @@ -87,12 +82,13 @@ public class RenderEntityEvents */ @SideOnly(Side.CLIENT) @SubscribeEvent - public void inputEvent(InputEvent event) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + public void inputEvent(InputEvent event) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { GameSettings settings = Minecraft.getMinecraft().gameSettings; Field field = KeyBinding.class.getDeclaredFields()[7]; field.setAccessible(true); ItemStack stack = Minecraft.getMinecraft().thePlayer.getHeldItemMainhand(); + EntityPlayer player = Minecraft.getMinecraft().thePlayer; if (stack != null ? stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack) : false) { if (settings.keyBindDrop.isPressed()) @@ -110,7 +106,13 @@ public class RenderEntityEvents field.set(keyBind, false); } } + } + + int current = player.inventory.currentItem; + + if (player.getEntityData().hasKey("carrySlot") ? player.getEntityData().getInteger("carrySlot") != current : false) + player.inventory.currentItem = player.getEntityData().getInteger("carrySlot"); } /* @@ -121,7 +123,6 @@ public class RenderEntityEvents public void renderHand(RenderHandEvent event) { - World world = Minecraft.getMinecraft().theWorld; EntityPlayer player = Minecraft.getMinecraft().thePlayer; AbstractClientPlayer aplayer = (AbstractClientPlayer) player; @@ -129,7 +130,6 @@ public class RenderEntityEvents int perspective = Minecraft.getMinecraft().gameSettings.thirdPersonView; float partialticks = event.getPartialTicks(); - if (stack != null ? stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack) : false) { BlockPos pos = player.getPosition(); @@ -154,27 +154,26 @@ public class RenderEntityEvents GlStateManager.rotate(180, 0, 1, 0); GlStateManager.translate(0.0, -height - .1, width + 0.1); GlStateManager.enableAlpha(); - - + if (perspective == 0) { RenderHelper.enableStandardItemLighting(); Minecraft.getMinecraft().getRenderManager().setRenderShadow(false); Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false); Minecraft.getMinecraft().getRenderManager().setRenderShadow(true); - + } GlStateManager.disableAlpha(); GlStateManager.scale(1, 1, 1); GlStateManager.popMatrix(); - + RenderHelper.disableStandardItemLighting(); GlStateManager.disableRescaleNormal(); - GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); - GlStateManager.disableTexture2D(); - GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); + GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GlStateManager.disableTexture2D(); + GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); if (perspective == 0) event.setCanceled(true); @@ -248,5 +247,4 @@ public class RenderEntityEvents } - } diff --git a/src/main/java/tschipp/carryon/client/event/RenderEvents.java b/src/main/java/tschipp/carryon/client/event/RenderEvents.java index 6f1e709..106cd9d 100644 --- a/src/main/java/tschipp/carryon/client/event/RenderEvents.java +++ b/src/main/java/tschipp/carryon/client/event/RenderEvents.java @@ -1,6 +1,8 @@ package tschipp.carryon.client.event; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -65,29 +67,32 @@ public class RenderEvents event.setCanceled(true); } } + } @SubscribeEvent @SideOnly(Side.CLIENT) - public void onPlayerTick(PlayerTickEvent event) + public void onPlayerTick(PlayerTickEvent event) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { EntityPlayer player = event.player; if (player != null && event.side == Side.CLIENT) { - + boolean keyPressed = CarryOnKeybinds.carryKey.isKeyDown(); boolean playerKeyPressed = CarryOnKeybinds.isKeyPressed(player); - + if (keyPressed && !playerKeyPressed) { CarryOnKeybinds.setKeyPressed(player, true); CarryOn.network.sendToServer(new SyncKeybindPacket(true)); } - else if(!keyPressed && playerKeyPressed) + else if (!keyPressed && playerKeyPressed) { CarryOnKeybinds.setKeyPressed(player, false); CarryOn.network.sendToServer(new SyncKeybindPacket(false)); } + + } } @@ -124,6 +129,7 @@ public class RenderEvents GameSettings settings = Minecraft.getMinecraft().gameSettings; Field field = KeyBinding.class.getDeclaredFields()[7]; field.setAccessible(true); + EntityPlayer player = Minecraft.getMinecraft().thePlayer; ItemStack stack = Minecraft.getMinecraft().thePlayer.getHeldItemMainhand(); if (stack != null ? stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack) : false) { @@ -142,7 +148,16 @@ public class RenderEvents field.set(keyBind, false); } } + } + + int current = player.inventory.currentItem; + + if(player.getEntityData().hasKey("carrySlot") ? player.getEntityData().getInteger("carrySlot") != current : false) + player.inventory.currentItem = player.getEntityData().getInteger("carrySlot"); + + + } /* diff --git a/src/main/java/tschipp/carryon/common/CommonProxy.java b/src/main/java/tschipp/carryon/common/CommonProxy.java index 29538cd..0683f9a 100644 --- a/src/main/java/tschipp/carryon/common/CommonProxy.java +++ b/src/main/java/tschipp/carryon/common/CommonProxy.java @@ -8,6 +8,8 @@ import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.relauncher.Side; import tschipp.carryon.CarryOn; import tschipp.carryon.common.handler.RegistrationHandler; +import tschipp.carryon.network.client.CarrySlotPacket; +import tschipp.carryon.network.client.CarrySlotPacketHandler; import tschipp.carryon.network.server.SyncKeybindPacket; import tschipp.carryon.network.server.SyncKeybindPacketHandler; @@ -20,7 +22,8 @@ public class CommonProxy CarryOn.network = NetworkRegistry.INSTANCE.newSimpleChannel("CarryOn"); CarryOn.network.registerMessage(SyncKeybindPacketHandler.class, SyncKeybindPacket.class, 0, Side.SERVER); - + CarryOn.network.registerMessage(CarrySlotPacketHandler.class, CarrySlotPacket.class, 1, Side.CLIENT); + RegistrationHandler.regItems(); RegistrationHandler.regCommonEvents(); } diff --git a/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java b/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java new file mode 100644 index 0000000..bdf06f3 --- /dev/null +++ b/src/main/java/tschipp/carryon/common/command/CommandCarryOn.java @@ -0,0 +1,185 @@ +package tschipp.carryon.common.command; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.command.WrongUsageException; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextComponentString; +import tschipp.carryon.CarryOn; +import tschipp.carryon.common.handler.ModelOverridesHandler; +import tschipp.carryon.common.handler.RegistrationHandler; +import tschipp.carryon.common.item.ItemEntity; +import tschipp.carryon.common.item.ItemTile; +import tschipp.carryon.network.client.CarrySlotPacket; + +public class CommandCarryOn extends CommandBase implements ICommand +{ + + private final List names; + + public CommandCarryOn() + { + names = new ArrayList(); + names.add("carryon"); + } + + @Override + public int compareTo(ICommand o) + { + return this.getCommandName().compareTo(o.getCommandName()); + } + + @Override + public String getCommandName() + { + return "carryon"; + } + + @Override + public String getCommandUsage(ICommandSender sender) + { + + return "/carryon "; + } + + @Override + public List getCommandAliases() + { + return this.names; + } + + + + @Override + public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException + { + if (args.length > 0) + { + // Handling clear + if (args[0].toLowerCase().equals("clear")) + { + if (sender instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer) sender; + + int cleared = 0; + cleared += player.inventory.clearMatchingItems(RegistrationHandler.itemTile, 0, 64, null); + cleared += player.inventory.clearMatchingItems(RegistrationHandler.itemEntity, 0, 64, null); + + CarryOn.network.sendTo(new CarrySlotPacket(9), (EntityPlayerMP) player); + + if (cleared != 1) + player.addChatMessage(new TextComponentString("Cleared " + cleared + " Items!")); + else + player.addChatMessage(new TextComponentString("Cleared " + cleared + " Item!")); + } + + } + // Handling debug + else if (args[0].toLowerCase().equals("debug")) + { + + if (sender instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer) sender; + ItemStack main = player.getHeldItemMainhand(); + if (main != null && main.getItem() == RegistrationHandler.itemTile) + { + player.addChatMessage(new TextComponentString("Block: " + ItemTile.getBlock(main))); + player.addChatMessage(new TextComponentString("BlockState: " + ItemTile.getBlockState(main))); + player.addChatMessage(new TextComponentString("Meta: " + ItemTile.getMeta(main))); + player.addChatMessage(new TextComponentString("ItemStack: " + ItemTile.getItemStack(main))); + + if(ModelOverridesHandler.hasCustomOverrideModel(ItemTile.getBlockState(main), ItemTile.getTileData(main))) + player.addChatMessage(new TextComponentString("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemTile.getBlockState(main), ItemTile.getTileData(main)))); + + CarryOn.LOGGER.info("Block: " + ItemTile.getBlock(main)); + CarryOn.LOGGER.info("BlockState: " + ItemTile.getBlockState(main)); + CarryOn.LOGGER.info("Meta: " + ItemTile.getMeta(main)); + CarryOn.LOGGER.info("ItemStack: " + ItemTile.getItemStack(main)); + + if(ModelOverridesHandler.hasCustomOverrideModel(ItemTile.getBlockState(main), ItemTile.getTileData(main))) + CarryOn.LOGGER.info("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemTile.getBlockState(main), ItemTile.getTileData(main))); + + } + else if(main != null && main.getItem() == RegistrationHandler.itemEntity) + { + player.addChatMessage(new TextComponentString("Entity: " + ItemEntity.getEntity(main, server.getEntityWorld()))); + player.addChatMessage(new TextComponentString("Entity Name: " + ItemEntity.getEntityName(main))); + + + CarryOn.LOGGER.info("Entity: " + ItemEntity.getEntity(main, server.getEntityWorld())); + CarryOn.LOGGER.info("Entity Name: " + ItemEntity.getEntityName(main)); + + + } + } + } + else + { + throw new WrongUsageException(this.getCommandUsage(sender)); + } + + } + else + { + throw new WrongUsageException(this.getCommandUsage(sender)); + } + + } + + @Override + public boolean checkPermission(MinecraftServer server, ICommandSender sender) + { + return true; + } + + + @Override + public List getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) + { + + if (args.length > 0) + { + if (args.length == 1) + { + return CommandBase.getListOfStringsMatchingLastWord(args, "debug", "clear"); + } + + else + { + return Collections.emptyList(); + } + + } + + return Collections.emptyList(); + + } + + @Override + public boolean isUsernameIndex(String[] args, int index) + { + + return false; + } + + @Override + public int getRequiredPermissionLevel() + { + return 2; + } + + + +} diff --git a/src/main/java/tschipp/carryon/common/config/Configs.java b/src/main/java/tschipp/carryon/common/config/Configs.java index 7db9296..7d57fca 100644 --- a/src/main/java/tschipp/carryon/common/config/Configs.java +++ b/src/main/java/tschipp/carryon/common/config/Configs.java @@ -70,8 +70,8 @@ public class Configs { "bigreactors:*", "forestry:*", "tconstruct:*", - "refinedstorage:*", "rustic:*", + "quark:colored_bed_*", "immersiveengineering:*", "embers:block_furnace", "embers:ember_bore", diff --git a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java index 1510011..4f31142 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEntityEvents.java @@ -18,10 +18,12 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.Event.Result; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import tschipp.carryon.CarryOn; import tschipp.carryon.client.keybinds.CarryOnKeybinds; import tschipp.carryon.common.handler.PickupHandler; import tschipp.carryon.common.handler.RegistrationHandler; import tschipp.carryon.common.item.ItemEntity; +import tschipp.carryon.network.client.CarrySlotPacket; public class ItemEntityEvents { @@ -33,6 +35,7 @@ public class ItemEntityEvents ItemStack stack = player.getHeldItemMainhand(); if (stack != null && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)) { + player.getEntityData().removeTag("carrySlot"); event.setUseBlock(Result.DENY); } @@ -78,13 +81,17 @@ public class ItemEntityEvents { ItemStack stack = new ItemStack(RegistrationHandler.itemEntity); - if (PickupHandler.canPlayerPickUpEntity(player, entity)) + if (entity.hurtResistantTime == 0) { - if (ItemEntity.storeEntityData(entity, world, stack)) + if (PickupHandler.canPlayerPickUpEntity(player, entity)) { - entity.setDead(); - player.setHeldItem(EnumHand.MAIN_HAND, stack); - event.setCanceled(true); + if (ItemEntity.storeEntityData(entity, world, stack)) + { + CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem), (EntityPlayerMP) player); + entity.setDead(); + player.setHeldItem(EnumHand.MAIN_HAND, stack); + event.setCanceled(true); + } } } @@ -111,7 +118,7 @@ public class ItemEntityEvents { float height = contained.height; float width = contained.width; - + entity.addVelocity(0, -0.01 * height * width, 0); } } diff --git a/src/main/java/tschipp/carryon/common/event/ItemEvents.java b/src/main/java/tschipp/carryon/common/event/ItemEvents.java index aa040d8..86bcfc2 100644 --- a/src/main/java/tschipp/carryon/common/event/ItemEvents.java +++ b/src/main/java/tschipp/carryon/common/event/ItemEvents.java @@ -2,30 +2,30 @@ package tschipp.carryon.common.event; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.player.PlayerEvent.StartTracking; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.fml.common.eventhandler.Event.Result; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import tschipp.carryon.CarryOn; import tschipp.carryon.client.keybinds.CarryOnKeybinds; -import tschipp.carryon.common.config.CarryOnConfig; import tschipp.carryon.common.handler.ForbiddenTileHandler; import tschipp.carryon.common.handler.PickupHandler; import tschipp.carryon.common.handler.RegistrationHandler; import tschipp.carryon.common.item.ItemTile; +import tschipp.carryon.network.client.CarrySlotPacket; public class ItemEvents { @@ -37,6 +37,7 @@ public class ItemEvents ItemStack stack = player.getHeldItemMainhand(); if (stack != null && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) { + player.getEntityData().removeTag("carrySlot"); event.setUseBlock(Result.DENY); } @@ -71,8 +72,11 @@ public class ItemEvents } world.setBlockState(finalPos, ItemTile.getBlockState(stack)); TileEntity tile = world.getTileEntity(finalPos); - tile.readFromNBT(ItemTile.getTileData(stack)); - tile.setPos(finalPos); + if (tile != null) + { + tile.readFromNBT(ItemTile.getTileData(stack)); + tile.setPos(finalPos); + } ItemTile.clearTileData(stack); eitem.setEntityItemStack(null); } @@ -80,7 +84,7 @@ public class ItemEvents } @SubscribeEvent - public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) + public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) throws InstantiationException, IllegalAccessException { EntityPlayer player = event.getEntityPlayer(); @@ -103,11 +107,19 @@ public class ItemEvents { if (ItemTile.storeTileData(te, world, pos, state.getActualState(world, pos), stack)) { - world.removeTileEntity(pos); + CarryOn.network.sendTo(new CarrySlotPacket(player.inventory.currentItem), (EntityPlayerMP) player); + if (world.getTileEntity(pos) != null) + { + TileEntity newtile = world.getTileEntity(pos).getClass().newInstance(); + world.removeTileEntity(pos); + world.setTileEntity(pos, newtile); + } world.setBlockToAir(pos); player.setHeldItem(EnumHand.MAIN_HAND, stack); event.setUseBlock(Result.DENY); event.setCanceled(true); + + } } diff --git a/src/main/java/tschipp/carryon/common/item/ItemTile.java b/src/main/java/tschipp/carryon/common/item/ItemTile.java index 598a00c..4fe183b 100644 --- a/src/main/java/tschipp/carryon/common/item/ItemTile.java +++ b/src/main/java/tschipp/carryon/common/item/ItemTile.java @@ -7,8 +7,6 @@ import java.util.List; import javax.annotation.Nullable; import net.minecraft.block.Block; -import net.minecraft.block.BlockDirectional; -import net.minecraft.block.BlockHorizontal; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.IBlockState; @@ -27,6 +25,10 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.event.ClickEvent; +import net.minecraft.util.text.event.ClickEvent.Action; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import tschipp.carryon.CarryOn; @@ -73,6 +75,8 @@ public class ItemTile extends Item if (istack != null) return istack.getDisplayName(); } + + return getItemStack(stack).getDisplayName(); } return ""; @@ -84,65 +88,85 @@ public class ItemTile extends Item Block block = world.getBlockState(pos).getBlock(); if (hasTileData(stack)) { - Vec3d vec = player.getLookVec(); - EnumFacing facing2 = EnumFacing.getFacingFromVector((float) vec.xCoord, 0f, (float) vec.zCoord); - BlockPos pos2 = pos; - Block containedblock = getBlock(stack); - int meta = getMeta(stack); - IBlockState containedstate = getBlockState(stack); - if (!world.getBlockState(pos2).getBlock().isReplaceable(world, pos2)) + try { - pos2 = pos.offset(facing); - } - - if (world.getBlockState(pos2).getBlock().isReplaceable(world, pos2) && containedblock != null) - { - boolean canPlace = containedblock.canPlaceBlockAt(world, pos2); - - if (canPlace) + Vec3d vec = player.getLookVec(); + EnumFacing facing2 = EnumFacing.getFacingFromVector((float) vec.xCoord, 0f, (float) vec.zCoord); + BlockPos pos2 = pos; + Block containedblock = getBlock(stack); + int meta = getMeta(stack); + IBlockState containedstate = getBlockState(stack); + if (!world.getBlockState(pos2).getBlock().isReplaceable(world, pos2)) { - boolean canEdit = player.canPlayerEdit(pos2, facing, stack); - boolean canBePlaced = world.canBlockBePlaced(containedblock, pos2, false, facing, (Entity) null, null); - if (canEdit && canBePlaced) + pos2 = pos.offset(facing); + } + + if (world.getBlockState(pos2).getBlock().isReplaceable(world, pos2) && containedblock != null) + { + boolean canPlace = containedblock.canPlaceBlockAt(world, pos2); + + if (canPlace) { - boolean hasDirection = false; - boolean hasAllDirection = false; - - Iterator> iterator = containedblock.getDefaultState().getPropertyNames().iterator(); - while (iterator.hasNext()) + if (player.canPlayerEdit(pos, facing, stack) && world.canBlockBePlaced(containedblock, pos2, false, facing, (Entity) null, stack)) { - IProperty prop = iterator.next(); - Object[] allowedValues = prop.getAllowedValues().toArray(); + boolean set = false; - if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.HORIZONTALS)) - hasDirection = true; - - if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.VALUES)) + Iterator> iterator = containedblock.getDefaultState().getPropertyNames().iterator(); + while (iterator.hasNext()) { - hasAllDirection = true; - facing2 = EnumFacing.getFacingFromVector((float) vec.xCoord, (float) vec.yCoord, (float) vec.zCoord); + IProperty prop = iterator.next(); + Object[] allowedValues = prop.getAllowedValues().toArray(); + + if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.HORIZONTALS)) + { + world.setBlockState(pos2, containedstate.withProperty(prop, facing2.getOpposite())); + set = true; + } + else if (prop instanceof PropertyDirection && this.equal(allowedValues, EnumFacing.VALUES)) + { + facing2 = EnumFacing.getFacingFromVector((float) vec.xCoord, (float) vec.yCoord, (float) vec.zCoord); + world.setBlockState(pos2, containedstate.withProperty(prop, facing2.getOpposite())); + set = true; + } + } + if (!set) + world.setBlockState(pos2, containedstate); + + TileEntity tile = world.getTileEntity(pos2); + if (tile != null) + { + tile.readFromNBT(getTileData(stack)); + tile.setPos(pos2); + } + clearTileData(stack); + player.playSound(containedblock.getSoundType().getPlaceSound(), 1.0f, 0.5f); + player.setHeldItem(hand, null); + return EnumActionResult.SUCCESS; } - if (hasAllDirection) - world.setBlockState(pos2, containedstate.withProperty(BlockDirectional.FACING, facing2.getOpposite())); - else if (hasDirection) - world.setBlockState(pos2, containedstate.withProperty(BlockHorizontal.FACING, facing2.getOpposite())); - else - world.setBlockState(pos2, containedstate); - - TileEntity tile = world.getTileEntity(pos2); - if (tile != null) - { - tile.readFromNBT(getTileData(stack)); - tile.setPos(pos2); - } - clearTileData(stack); - player.playSound(containedblock.getSoundType().getPlaceSound(), 1.0f, 0.5f); - player.setHeldItem(hand, null); - return EnumActionResult.SUCCESS; } + } + } + catch (Exception e) + { + e.printStackTrace(); + + if (world.isRemote) + { + CarryOn.LOGGER.info("Block: " + ItemTile.getBlock(stack)); + CarryOn.LOGGER.info("BlockState: " + ItemTile.getBlockState(stack)); + CarryOn.LOGGER.info("Meta: " + ItemTile.getMeta(stack)); + CarryOn.LOGGER.info("ItemStack: " + ItemTile.getItemStack(stack)); + + if (ModelOverridesHandler.hasCustomOverrideModel(ItemTile.getBlockState(stack), ItemTile.getTileData(stack))) + CarryOn.LOGGER.info("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemTile.getBlockState(stack), ItemTile.getTileData(stack))); + + player.addChatMessage(new TextComponentString(TextFormatting.RED + "Error detected. Cannot place block. Execute \"/carryon clear\" to remove the item")); + TextComponentString s = new TextComponentString(TextFormatting.GOLD + "here"); + s.getStyle().setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/Tschipp/CarryOn/issues")); + player.addChatMessage(new TextComponentString(TextFormatting.RED + "Please report this error ").appendSibling(s)); } } diff --git a/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java b/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java new file mode 100644 index 0000000..1f53e07 --- /dev/null +++ b/src/main/java/tschipp/carryon/network/client/CarrySlotPacket.java @@ -0,0 +1,32 @@ +package tschipp.carryon.network.client; + +import io.netty.buffer.ByteBuf; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; + +public class CarrySlotPacket implements IMessage +{ + public int slot; + + public CarrySlotPacket() + { + } + + public CarrySlotPacket(int slot) + { + this.slot = slot; + } + + @Override + public void fromBytes(ByteBuf buf) + { + this.slot = ByteBufUtils.readVarInt(buf, 4); + } + + @Override + public void toBytes(ByteBuf buf) + { + ByteBufUtils.writeVarInt(buf, slot, 4); + } + +} diff --git a/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java b/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java new file mode 100644 index 0000000..0b28f75 --- /dev/null +++ b/src/main/java/tschipp/carryon/network/client/CarrySlotPacketHandler.java @@ -0,0 +1,37 @@ +package tschipp.carryon.network.client; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.util.IThreadListener; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import tschipp.carryon.client.keybinds.CarryOnKeybinds; + +public class CarrySlotPacketHandler implements IMessageHandler +{ + + @Override + public IMessage onMessage(final CarrySlotPacket message, final MessageContext ctx) + { + IThreadListener mainThread = Minecraft.getMinecraft(); + + mainThread.addScheduledTask(new Runnable() + { + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + + @Override + public void run() + { + if (message.slot >= 9) + player.getEntityData().removeTag("carrySlot"); + else + player.getEntityData().setInteger("carrySlot", message.slot); + } + + }); + + return null; + } + +} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index dc12efc..5da688d 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -2,7 +2,7 @@ { "modid" : "carryon", "name" : "Carry On", - "version" : "1.3", "mcversion" : "1.10.2", + "version" : "1.4", "mcversion" : "1.10.2", "url" : "", "credits" : "Tschipp, Purplicious_Cow, cy4n", "authorList" : ["Tschipp, Purplicious_Cow, cy4n"],