Bugfixes
This commit is contained in:
parent
66dffa7350
commit
e603944f2e
|
|
@ -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", dependencies = "required-after:forge@[13.20.1.2386,)", 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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().player.getHeldItemMainhand();
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
|
||||
{
|
||||
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().world;
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
AbstractClientPlayer aplayer = (AbstractClientPlayer) player;
|
||||
|
|
@ -129,7 +130,6 @@ public class RenderEntityEvents
|
|||
int perspective = Minecraft.getMinecraft().gameSettings.thirdPersonView;
|
||||
float partialticks = event.getPartialTicks();
|
||||
|
||||
|
||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
|
||||
{
|
||||
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
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,6 +130,7 @@ public class RenderEvents
|
|||
Field field = KeyBinding.class.getDeclaredFields()[7];
|
||||
field.setAccessible(true);
|
||||
ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand();
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack))
|
||||
{
|
||||
if (settings.keyBindDrop.isPressed())
|
||||
|
|
@ -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");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
192
src/main/java/tschipp/carryon/common/command/CommandCarryOn.java
Normal file
192
src/main/java/tschipp/carryon/common/command/CommandCarryOn.java
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
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.CustomPickupOverrideHandler;
|
||||
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.getName().compareTo(o.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "carryon";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender)
|
||||
{
|
||||
|
||||
return "/carryon <mode>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAliases()
|
||||
{
|
||||
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.sendMessage(new TextComponentString("Cleared " + cleared + " Items!"));
|
||||
else
|
||||
player.sendMessage(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.isEmpty() && main.getItem() == RegistrationHandler.itemTile)
|
||||
{
|
||||
player.sendMessage(new TextComponentString("Block: " + ItemTile.getBlock(main)));
|
||||
player.sendMessage(new TextComponentString("BlockState: " + ItemTile.getBlockState(main)));
|
||||
player.sendMessage(new TextComponentString("Meta: " + ItemTile.getMeta(main)));
|
||||
player.sendMessage(new TextComponentString("ItemStack: " + ItemTile.getItemStack(main)));
|
||||
|
||||
if(ModelOverridesHandler.hasCustomOverrideModel(ItemTile.getBlockState(main), ItemTile.getTileData(main)))
|
||||
player.sendMessage(new TextComponentString("Override Model: " + ModelOverridesHandler.getOverrideObject(ItemTile.getBlockState(main), ItemTile.getTileData(main))));
|
||||
|
||||
if(CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemTile.getBlockState(main)))
|
||||
player.sendMessage(new TextComponentString("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemTile.getBlockState(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)));
|
||||
|
||||
if(CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemTile.getBlockState(main)))
|
||||
CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemTile.getBlockState(main)));
|
||||
|
||||
}
|
||||
else if(!main.isEmpty() && main.getItem() == RegistrationHandler.itemEntity)
|
||||
{
|
||||
player.sendMessage(new TextComponentString("Entity: " + ItemEntity.getEntity(main, server.getEntityWorld())));
|
||||
player.sendMessage(new TextComponentString("Entity Name: " + ItemEntity.getEntityName(main)));
|
||||
|
||||
if(CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemEntity.getEntity(main, server.getEntityWorld())))
|
||||
player.sendMessage(new TextComponentString("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemEntity.getEntity(main, server.getEntityWorld()))));
|
||||
|
||||
CarryOn.LOGGER.info("Entity: " + ItemEntity.getEntity(main, server.getEntityWorld()));
|
||||
CarryOn.LOGGER.info("Entity Name: " + ItemEntity.getEntityName(main));
|
||||
|
||||
if(CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemEntity.getEntity(main, server.getEntityWorld())))
|
||||
CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemEntity.getEntity(main, server.getEntityWorld())));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException(this.getUsage(sender));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WrongUsageException(this.getUsage(sender));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletions(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.<String>emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return Collections.<String>emptyList();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsernameIndex(String[] args, int index)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -71,8 +71,8 @@ public class Configs {
|
|||
"bigreactors:*",
|
||||
"forestry:*",
|
||||
"tconstruct:*",
|
||||
"refinedstorage:*",
|
||||
"rustic:*",
|
||||
"quark:colored_bed_*",
|
||||
"immersiveengineering:*",
|
||||
"embers:block_furnace",
|
||||
"embers:ember_bore",
|
||||
|
|
|
|||
|
|
@ -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.isEmpty() && 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.isEmpty() && 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(ItemStack.EMPTY);
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,16 @@ 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.util.text.translation.I18n;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import tschipp.carryon.CarryOn;
|
||||
import tschipp.carryon.common.config.CarryOnConfig;
|
||||
import tschipp.carryon.common.handler.CustomPickupOverrideHandler;
|
||||
import tschipp.carryon.common.handler.ModelOverridesHandler;
|
||||
|
||||
public class ItemTile extends Item
|
||||
|
|
@ -53,12 +59,12 @@ public class ItemTile extends Item
|
|||
{
|
||||
IBlockState state = getBlockState(stack);
|
||||
NBTTagCompound nbt = getTileData(stack);
|
||||
|
||||
if(ModelOverridesHandler.hasCustomOverrideModel(state, nbt))
|
||||
|
||||
if (ModelOverridesHandler.hasCustomOverrideModel(state, nbt))
|
||||
{
|
||||
Object override = ModelOverridesHandler.getOverrideObject(state, nbt);
|
||||
if(override instanceof ItemStack)
|
||||
return ((ItemStack)override).getDisplayName();
|
||||
if (override instanceof ItemStack)
|
||||
return ((ItemStack) override).getDisplayName();
|
||||
else
|
||||
{
|
||||
IBlockState ostate = (IBlockState) override;
|
||||
|
|
@ -66,7 +72,7 @@ public class ItemTile extends Item
|
|||
return itemstack.getDisplayName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return getItemStack(stack).getDisplayName();
|
||||
}
|
||||
|
||||
|
|
@ -80,63 +86,88 @@ public class ItemTile extends Item
|
|||
ItemStack stack = player.getHeldItem(hand);
|
||||
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))
|
||||
{
|
||||
if (player.canPlayerEdit(pos, facing, stack) && world.mayPlace(containedblock, pos2, false, facing, (Entity) null))
|
||||
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<IProperty<?>> iterator = containedblock.getDefaultState().getPropertyKeys().iterator();
|
||||
while (iterator.hasNext())
|
||||
if (player.canPlayerEdit(pos, facing, stack) && world.mayPlace(containedblock, pos2, false, facing, (Entity) null))
|
||||
{
|
||||
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<IProperty<?>> iterator = containedblock.getDefaultState().getPropertyKeys().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, ItemStack.EMPTY);
|
||||
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, ItemStack.EMPTY);
|
||||
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)));
|
||||
|
||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(ItemTile.getBlockState(stack)))
|
||||
CarryOn.LOGGER.info("Custom Pickup Condition: " + CustomPickupOverrideHandler.getPickupCondition(ItemTile.getBlockState(stack)));
|
||||
|
||||
player.sendMessage(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.sendMessage(new TextComponentString(TextFormatting.RED + "Please report this error ").appendSibling(s));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -153,9 +184,9 @@ public class ItemTile extends Item
|
|||
{
|
||||
if (entity instanceof EntityLivingBase)
|
||||
{
|
||||
if(entity instanceof EntityPlayer && CarryOnConfig.settings.slownessInCreative ? false : ((EntityPlayer)entity).isCreative())
|
||||
if (entity instanceof EntityPlayer && CarryOnConfig.settings.slownessInCreative ? false : ((EntityPlayer) entity).isCreative())
|
||||
return;
|
||||
|
||||
|
||||
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 1, potionLevel(stack), false, false));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<CarrySlotPacket, IMessage>
|
||||
{
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(final CarrySlotPacket message, final MessageContext ctx)
|
||||
{
|
||||
IThreadListener mainThread = Minecraft.getMinecraft();
|
||||
|
||||
mainThread.addScheduledTask(new Runnable()
|
||||
{
|
||||
EntityPlayerSP player = Minecraft.getMinecraft().player;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (message.slot >= 9)
|
||||
player.getEntityData().removeTag("carrySlot");
|
||||
else
|
||||
player.getEntityData().setInteger("carrySlot", message.slot);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
"modid" : "carryon",
|
||||
"name" : "Carry On",
|
||||
"version" : "1.3", "mcversion" : "1.11.2",
|
||||
"version" : "1.4", "mcversion" : "1.11.2",
|
||||
"url" : "",
|
||||
"credits" : "Tschipp, Purplicious_Cow, cy4n",
|
||||
"authorList" : ["Tschipp, Purplicious_Cow, cy4n"],
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user