Update to 1.2

This commit is contained in:
Tschipp 2017-08-20 00:26:58 +02:00
commit 20294c004d
18 changed files with 1088 additions and 153 deletions

View File

@ -1,4 +1,2 @@
# CarryOn
Carry On mod for Minecraft
Download here: https://minecraft.curseforge.com/projects/carry-on
# Carry On [![](http://cf.way2muchnoise.eu/carry-on.svg)](https://minecraft.curseforge.com/projects/carry-on) [![](http://cf.way2muchnoise.eu/versions/carry-on.svg)](https://minecraft.curseforge.com/projects/carry-on)

View File

@ -2,11 +2,16 @@ buildscript {
repositories {
jcenter()
maven { url = "http://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
version = "1.0"
@ -26,8 +31,26 @@ minecraft {
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}
repositories {
maven { url 'http://maven.epoxide.org' }
ivy {
name "LatMod"
artifactPattern "http://mods.latmod.com/[module]/[revision]/[module]-[revision](-[classifier]).[ext]"
}
}
dependencies {
deobfCompile "net.darkhax.gamestages:GameStages-1.11.2:1.0.11"
deobfCompile "LatMod:FTBUtilities:1.1x-3.6.5"
deobfCompile "LatMod:FTBLib:1.1x-3.6.5"
}
processResources {

View File

@ -26,7 +26,7 @@ public class CarryOn {
public static CarryOn instance;
public static final String MODID = "carryon";
public static final String VERSION = "1.1.1";
public static final String VERSION = "1.2";
public static final String NAME = "Carry On";
public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/bf7fb60d5e59f73eee65b271d5c01585e26a0352/update.json";
public static final Logger LOGGER = LogManager.getFormatterLogger("CarryOn");

View File

@ -0,0 +1,276 @@
package tschipp.carryon.client.event;
import java.lang.reflect.Field;
import org.lwjgl.opengl.GL11;
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.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;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tschipp.carryon.common.handler.RegistrationHandler;
import tschipp.carryon.common.item.ItemEntity;
import tschipp.carryon.common.item.ItemTile;
public class RenderEntityEvents
{
/*
* Prevents the Player from scrolling
*/
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onScroll(MouseEvent event)
{
if (event.getDwheel() > 0 || event.getDwheel() < 0)
{
ItemStack stack = Minecraft.getMinecraft().thePlayer.getHeldItemMainhand();
if (stack != null && stack.getItem() == RegistrationHandler.itemEntity)
{
if (ItemEntity.hasEntityData(stack))
event.setCanceled(true);
}
}
}
/*
* Prevents the Player from opening Guis
*/
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event)
{
if (event.getGui() != null)
{
boolean inventory = event.getGui() instanceof GuiContainer;
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (player != null)
{
ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
if (inventory && stack != null && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
{
event.setCanceled(true);
Minecraft.getMinecraft().currentScreen = null;
}
}
}
}
/*
* Prevents the Player from switching Slots
*/
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void inputEvent(InputEvent event) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
{
GameSettings settings = Minecraft.getMinecraft().gameSettings;
Field field = KeyBinding.class.getDeclaredFields()[7];
field.setAccessible(true);
ItemStack stack = Minecraft.getMinecraft().thePlayer.getHeldItemMainhand();
if (stack != null && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
{
if (settings.keyBindDrop.isPressed())
{
field.set(settings.keyBindDrop, false);
}
if (settings.keyBindSwapHands.isPressed())
{
field.set(settings.keyBindSwapHands, false);
}
for (KeyBinding keyBind : settings.keyBindsHotbar)
{
if (keyBind.isPressed())
{
field.set(keyBind, false);
}
}
}
}
/*
* Renders the Entity in First Person
*/
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void renderHand(RenderHandEvent event)
{
World world = Minecraft.getMinecraft().theWorld;
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
AbstractClientPlayer aplayer = (AbstractClientPlayer) player;
ItemStack stack = player.getHeldItemMainhand();
int perspective = Minecraft.getMinecraft().gameSettings.thirdPersonView;
float partialticks = event.getPartialTicks();
if (stack != null && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
{
BlockPos pos = player.getPosition();
Entity entity = ItemEntity.getEntity(stack, world);
if (entity != null)
{
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialticks;
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialticks;
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialticks;
entity.setPosition(d0, d1, d2);
entity.rotationYaw = 0.0f;
entity.prevRotationYaw = 0.0f;
entity.setRotationYawHead(0.0f);
float height = entity.height;
float width = entity.width;
float multiplier = height * width;
GlStateManager.pushMatrix();
GlStateManager.scale(.8, .8, .8);
GlStateManager.rotate(180, 0, 1, 0);
GlStateManager.translate(0.0, -height - .1, width + 0.1);
GlStateManager.enableAlpha();
if (perspective == 0 && Minecraft.getMinecraft().inGameHasFocus)
{
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();
if (perspective == 0)
event.setCanceled(true);
}
}
}
/*
* Renders the Block in Third Person
*/
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onPlayerRenderPost(RenderPlayerEvent.Post event)
{
World world = Minecraft.getMinecraft().theWorld;
EntityPlayer player = event.getEntityPlayer();
ModelPlayer modelPlayer = event.getRenderer().getMainModel();
EntityPlayerSP clientPlayer = Minecraft.getMinecraft().thePlayer;
ItemStack stack = player.getHeldItemMainhand();
float partialticks = event.getPartialRenderTick();
if (stack != null && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
{
Entity entity = ItemEntity.getEntity(stack, world);
float rotation = -player.renderYawOffset;
int perspective = Minecraft.getMinecraft().gameSettings.thirdPersonView;
if (entity != null)
{
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialticks;
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialticks;
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialticks;
double c0 = clientPlayer.lastTickPosX + (clientPlayer.posX - clientPlayer.lastTickPosX) * (double) partialticks;
double c1 = clientPlayer.lastTickPosY + (clientPlayer.posY - clientPlayer.lastTickPosY) * (double) partialticks;
double c2 = clientPlayer.lastTickPosZ + (clientPlayer.posZ - clientPlayer.lastTickPosZ) * (double) partialticks;
double xOffset = d0 - c0;
double yOffset = d1 - c1;
double zOffset = d2 - c2;
float height = entity.height;
float width = entity.width;
float multiplier = height * width;
entity.setPosition(c0, c1, c2);
entity.rotationYaw = 0.0f;
entity.prevRotationYaw = 0.0f;
entity.setRotationYawHead(0.0f);
GlStateManager.pushMatrix();
GlStateManager.translate(xOffset, yOffset, zOffset);
GlStateManager.scale((10 - multiplier) * 0.08, (10 - multiplier) * 0.08, (10 - multiplier) * 0.08);
GlStateManager.rotate(rotation, 0, 1f, 0);
GlStateManager.translate(0.0, (height / 2) + -(height / 2) + 1, (width - 0.1) < 0.7 ? (width - 0.1) + (0.7 - (width - 0.1)) : (width - 0.1));
if (player.isSneaking())
GlStateManager.translate(0, -0.3, 0);
Minecraft.getMinecraft().getRenderManager().setRenderShadow(false);
Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false);
Minecraft.getMinecraft().getRenderManager().setRenderShadow(true);
GlStateManager.scale(1, 1, 1);
GlStateManager.popMatrix();
}
}
}
public void renderEntityStaticCO(Entity entityIn, float partialTicks, boolean p_188388_3_)
{
if (entityIn.ticksExisted == 0)
{
entityIn.lastTickPosX = entityIn.posX;
entityIn.lastTickPosY = entityIn.posY;
entityIn.lastTickPosZ = entityIn.posZ;
}
double d0 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks;
double d1 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks;
double d2 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks;
float f = entityIn.prevRotationYaw + (entityIn.rotationYaw - entityIn.prevRotationYaw) * partialTicks;
int i = 0;
if (!Minecraft.getMinecraft().theWorld.isDaytime()) {
i = entityIn.getBrightnessForRender(partialTicks);
} else {
i = 50000;
}
if (entityIn.isBurning())
{
i = 15728880;
}
int j = i % 65536;
int k = i / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j, (float)k);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
RenderManager manager = Minecraft.getMinecraft().getRenderManager();
manager.doRenderEntity(entityIn, d0, d1, d2, f, partialTicks, p_188388_3_);
}
}

View File

@ -1,6 +1,8 @@
package tschipp.carryon.client.event;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@ -8,7 +10,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.GlStateManager;
@ -21,6 +22,7 @@ import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
@ -31,6 +33,7 @@ import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.relauncher.Side;
@ -38,6 +41,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.handler.ModelOverridesHandler;
import tschipp.carryon.common.handler.RegistrationHandler;
import tschipp.carryon.common.item.ItemEntity;
import tschipp.carryon.common.item.ItemTile;
public class RenderEvents
@ -149,8 +153,21 @@ public class RenderEvents
GlStateManager.rotate(8, 1f, 0, 0);
if (perspective == 0)
Minecraft.getMinecraft().getRenderItem().renderItem(tileStack == null ? stack : tileStack, ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileStack, world, player));
{
IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, world, player) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileStack == null ? stack : tileStack, world, player);
if (ModelOverridesHandler.hasCustomOverrideModel(state, tag))
{
Object override = ModelOverridesHandler.getOverrideObject(state, tag);
if (override instanceof ItemStack)
{
Minecraft.getMinecraft().getRenderItem().renderItem((ItemStack) override, model);
}
else
Minecraft.getMinecraft().getRenderItem().renderItem(tileStack == null ? stack : tileStack, model);
}
else
Minecraft.getMinecraft().getRenderItem().renderItem(tileStack == null ? stack : tileStack, model);
}
GlStateManager.scale(1, 1, 1);
GlStateManager.popMatrix();
@ -159,13 +176,16 @@ public class RenderEvents
}
else
{
event.setCanceled(false);
Minecraft mc = Minecraft.getMinecraft();
RenderManager manager = mc.getRenderManager();
RenderPlayer renderPlayer = manager.getSkinMap().get(aplayer.getSkinType());
ModelPlayer modelPlayer = renderPlayer.getMainModel();
modelPlayer.bipedLeftArm.isHidden = false;
modelPlayer.bipedRightArm.isHidden = false;
if (stack == null ? true : stack.getItem() != RegistrationHandler.itemEntity)
{
event.setCanceled(false);
Minecraft mc = Minecraft.getMinecraft();
RenderManager manager = mc.getRenderManager();
RenderPlayer renderPlayer = manager.getSkinMap().get(aplayer.getSkinType());
ModelPlayer modelPlayer = renderPlayer.getMainModel();
modelPlayer.bipedLeftArm.isHidden = false;
modelPlayer.bipedRightArm.isHidden = false;
}
}
}
@ -181,7 +201,7 @@ public class RenderEvents
ModelPlayer modelPlayer = event.getRenderer().getMainModel();
EntityPlayerSP clientPlayer = Minecraft.getMinecraft().thePlayer;
ItemStack stack = player.getHeldItemMainhand();
if (stack != null && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack))
float partialticks = event.getPartialRenderTick();
{
Block block = ItemTile.getBlock(stack);
IBlockState state = ItemTile.getBlockState(stack);
@ -196,9 +216,17 @@ public class RenderEvents
float rotation = -player.renderYawOffset;
int perspective = Minecraft.getMinecraft().gameSettings.thirdPersonView;
double xOffset = (double) player.posX - (double) clientPlayer.posX;
double yOffset = (double) player.posY - (double) clientPlayer.posY;
double zOffset = (double) player.posZ - (double) clientPlayer.posZ;
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) partialticks;
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) partialticks;
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) partialticks;
double c0 = clientPlayer.lastTickPosX + (clientPlayer.posX - clientPlayer.lastTickPosX) * (double) partialticks;
double c1 = clientPlayer.lastTickPosY + (clientPlayer.posY - clientPlayer.lastTickPosY) * (double) partialticks;
double c2 = clientPlayer.lastTickPosZ + (clientPlayer.posZ - clientPlayer.lastTickPosZ) * (double) partialticks;
double xOffset = d0 - c0;
double yOffset = d1 - c1;
double zOffset = d2 - c2;
GlStateManager.pushMatrix();
GlStateManager.translate(xOffset, yOffset, zOffset);
@ -218,18 +246,24 @@ public class RenderEvents
if (player.isSneaking())
GlStateManager.translate(0, -0.3, 0);
IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileItem, world, player);
Minecraft.getMinecraft().getRenderItem().renderItem(tileItem == null ? stack : tileItem, model);
IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, world, player) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileItem == null ? stack : tileItem, world, player);
if (ModelOverridesHandler.hasCustomOverrideModel(state, tag))
{
Object override = ModelOverridesHandler.getOverrideObject(state, tag);
if (override instanceof ItemStack)
{
Minecraft.getMinecraft().getRenderItem().renderItem((ItemStack) override, model);
}
else
Minecraft.getMinecraft().getRenderItem().renderItem(tileItem == null ? stack : tileItem, model);
}
else
Minecraft.getMinecraft().getRenderItem().renderItem(tileItem == null ? stack : tileItem, model);
GlStateManager.scale(1, 1, 1);
GlStateManager.popMatrix();
}
else
{
modelPlayer.bipedLeftArm.isHidden = false;
modelPlayer.bipedRightArm.isHidden = false;
}
}
@ -240,74 +274,106 @@ public class RenderEvents
@SubscribeEvent
public void onPlayerRenderPre(RenderPlayerEvent.Pre event)
{
EntityPlayer player = event.getEntityPlayer();
AbstractClientPlayer aplayer = (AbstractClientPlayer) player;
ItemStack stack = player.getHeldItemMainhand();
ModelPlayer model = event.getRenderer().getMainModel();
EntityPlayerSP clientPlayer = Minecraft.getMinecraft().thePlayer;
if (!Loader.isModLoaded("mobends")) {
ResourceLocation skinLoc = DefaultPlayerSkin.getDefaultSkin(player.getPersistentID());
EntityPlayer player = event.getEntityPlayer();
AbstractClientPlayer aplayer = (AbstractClientPlayer) player;
ItemStack stack = player.getHeldItemMainhand();
ModelPlayer model = event.getRenderer().getMainModel();
EntityPlayerSP clientPlayer = Minecraft.getMinecraft().thePlayer;
ResourceLocation skinLoc = DefaultPlayerSkin.getDefaultSkin(player.getPersistentID());
ModelRenderer fakeLeftArm = new ModelRenderer(model, 32, 48);
ModelRenderer fakeRightArm = new ModelRenderer(model, 40, 16);
if (stack != null && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack))
{
if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty())
model.bipedBody.childModels.clear();
model.bipedLeftArm.isHidden = true;
model.bipedRightArm.isHidden = true;
Minecraft.getMinecraft().getTextureManager().bindTexture(skinLoc);
float rotation = -player.renderYawOffset;
if (aplayer.getSkinType().equals("default"))
ModelRenderer fakeLeftArm = new ModelRenderer(model, 32, 48);
ModelRenderer fakeRightArm = new ModelRenderer(model, 40, 16);
player.setArrowCountInEntity(0); //TODO Temporary Fix
if (stack != null && (stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) || (stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)))
{
fakeLeftArm.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 4, 12, 4, .08F);
if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty()) {
model.bipedBody.childModels.clear();
}
Item item = stack.getItem();
model.bipedLeftArm.isHidden = true;
model.bipedRightArm.isHidden = true;
Minecraft.getMinecraft().getTextureManager().bindTexture(skinLoc);
float rotation = -player.renderYawOffset;
if (aplayer.getSkinType().equals("default"))
{
fakeLeftArm.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 4, 12, 4, .08F);
}
else
{
fakeLeftArm.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 3, 12, 4, .08F);
}
if (aplayer.getSkinType().equals("default"))
{
fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.9F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 4, 12, 4, .08F);
}
else
{
fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.2F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 3, 12, 4, .08F);
}
if (item == RegistrationHandler.itemTile)
{
if (!player.isSneaking())
{
fakeRightArm.rotateAngleX = -.9F;
fakeLeftArm.rotateAngleX = -.9F;
}
else
{
fakeRightArm.rotateAngleX = -1.4F;
fakeLeftArm.rotateAngleX = -1.4F;
}
}
else
{
if (!player.isSneaking())
{
fakeRightArm.rotateAngleX = -1.2F;
fakeLeftArm.rotateAngleX = -1.2F;
}
else
{
fakeRightArm.rotateAngleX = -1.7F;
fakeLeftArm.rotateAngleX = -1.7F;
}
fakeRightArm.rotateAngleY = -0.15f;
fakeLeftArm.rotateAngleY = 0.15f;
}
model.bipedBody.addChild(fakeLeftArm);
model.bipedBody.addChild(fakeRightArm);
}
else
{
fakeLeftArm.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 3, 12, 4, .08F);
model.bipedLeftArm.isHidden = false;
model.bipedRightArm.isHidden = false;
if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty())
{
model.bipedBody.childModels.clear();
}
}
if (aplayer.getSkinType().equals("default"))
if (stack == null || (stack != null && stack.getItem() != RegistrationHandler.itemTile && stack.getItem() != RegistrationHandler.itemEntity))
{
fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.9F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 4, 12, 4, .08F);
}
else
{
fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.2F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 3, 12, 4, .08F);
}
if (!player.isSneaking())
{
fakeRightArm.rotateAngleX = -.9F;
fakeLeftArm.rotateAngleX = -.9F;
}
else
{
fakeRightArm.rotateAngleX = -1.4F;
fakeLeftArm.rotateAngleX = -1.4F;
}
model.bipedBody.addChild(fakeLeftArm);
model.bipedBody.addChild(fakeRightArm);
}
else
{
model.bipedLeftArm.isHidden = false;
model.bipedRightArm.isHidden = false;
if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty())
{
model.bipedBody.childModels.clear();
model.bipedLeftArm.isHidden = false;
model.bipedRightArm.isHidden = false;
}
}
if (stack == null || stack.getItem() != RegistrationHandler.itemTile || !ItemTile.hasTileData(stack))
{
model.bipedLeftArm.isHidden = false;
model.bipedRightArm.isHidden = false;
}
}
@ -330,4 +396,17 @@ public class RenderEvents
return getRenderPlayer(player).getMainModel();
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void hideItems(RenderPlayerEvent.Specials.Pre event)
{
EntityPlayer player = event.getEntityPlayer();
ItemStack stack = player.getHeldItemMainhand();
if (stack != null && (stack.getItem() == RegistrationHandler.itemTile || stack.getItem() == RegistrationHandler.itemEntity))
{
event.setRenderItem(false);
}
}
}

View File

@ -24,8 +24,8 @@ public class CarryOnConfig {
public static Configs.Settings settings = new Configs.Settings();
@Config.LangKey(CarryOn.MODID)
@Config.Comment("Tile Entities that the Player is not allowed to pick up")
public static Configs.ForbiddenTiles forbiddenTiles = new Configs.ForbiddenTiles();
@Config.Comment("Blacklist for Blocks and Entities")
public static Configs.Blacklist blacklist = new Configs.Blacklist();
@Config.LangKey(CarryOn.MODID)
@Config.Comment("Model Overrides based on NBT or on Meta. Advanced Users Only!")

View File

@ -16,11 +16,29 @@ public class Configs {
@Comment("Allow all blocks to be picked up, not just Tile Entites")
public boolean pickupAllBlocks = false;
@Comment("Maximum distance from where Blocks can be picked up")
@Comment("Whether Blocks and Entities slow the creative player down when carried")
public boolean slownessInCreative = true;
@Config.RangeDouble(min = 0)
@Comment("Maximum distance from where Blocks and Entities can be picked up")
public double maxDistance = 2.5;
@Config.RangeDouble(min = 0, max = 10)
@Comment("Max width of entities that can be picked up in survival mode")
public float maxEntityWidth = 1.5f;
@Config.RangeDouble(min = 0, max = 10)
@Comment("Max height of entities that can be picked up in survival mode")
public float maxEntityHeight = 1.5f;
@Comment("Whether hostile mobs should be able to picked up in survival mode")
public boolean pickupHostileMobs = false;
@Comment("Larger Entities slow down the player more")
public boolean heavyEntities = true;
}
public static class ForbiddenTiles
public static class Blacklist
{
@Comment("Tile Entities that cannot be picked up")
public String[] forbiddenTiles = new String[]
@ -29,6 +47,13 @@ public class Configs {
"minecraft:end_gateway",
"minecraft:double_plant",
"minecraft:bed",
"minecraft:wooden_door",
"minecraft:iron_door",
"minecraft:spruce_door",
"minecraft:birch_door",
"minecraft:jungle_door",
"minecraft:acacia_door",
"minecraft:dark_oak_door",
"animania:block_trough",
"animania:block_invisiblock",
"colossalchests:*",
@ -52,6 +77,16 @@ public class Configs {
"embers:inferno_forge",
"storagedrawers:framingtable",
};
@Comment("Entities that cannot be picked up")
public String[] forbiddenEntities = new String[]
{
"EnderCrystal",
"EnderDragon",
"Ghast",
"Shulker",
"animania:textures/entity/pigs/hamster_tarou.png"
};
}
public static class ModelOverrides
@ -60,7 +95,17 @@ public class Configs {
public String[] modelOverrides = new String[]
{
"minecraft:lit_furnace->minecraft:furnace",
"minecraft:bed->minecraft:bed",
"minecraft:hopper->(block)minecraft:hopper",
"minecraft:unpowered_comparator->(block)minecraft:unpowered_comparator",
"minecraft:unpowered_repeater->(block)minecraft:unpowered_repeater",
"minecraft:powered_comparator->(block)minecraft:powered_comparator",
"minecraft:powered_repeater->(block)minecraft:powered_repeater",
"minecraft:cauldron->(block)minecraft:cauldron",
"minecraft:brewing_stand->(item)minecraft:brewing_stand",
"minecraft:tallgrass;1->(item)minecraft:tallgrass;1",
"minecraft:tallgrass;2->(item)minecraft:tallgrass;2",
"minecraft:flower_pot->(block)minecraft:flower_pot",
"minecraft:leaves2->(item)minecraft:leaves2",
"quark:custom_chest{type:\"spruce\"}->quark:custom_chest;0",
"quark:custom_chest{type:\"birch\"}->quark:custom_chest;1",
"quark:custom_chest{type:\"jungle\"}->quark:custom_chest;2",
@ -98,5 +143,6 @@ public class Configs {
"storagedrawers:basicdrawers;4{Mat:\"dark_oak\"}->storagedrawers:basicdrawers;4{material:\"dark_oak\"}"
};
}
}

View File

@ -0,0 +1,91 @@
package tschipp.carryon.common.event;
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.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.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.common.handler.PickupHandler;
import tschipp.carryon.common.handler.RegistrationHandler;
import tschipp.carryon.common.item.ItemEntity;
public class ItemEntityEvents
{
@SubscribeEvent(priority = EventPriority.HIGH)
public void onBlockClick(PlayerInteractEvent.RightClickBlock event)
{
EntityPlayer player = event.getEntityPlayer();
ItemStack stack = player.getHeldItemMainhand();
if (stack != null && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
{
event.setUseBlock(Result.DENY);
}
}
@SubscribeEvent(priority = EventPriority.HIGH)
public void onItemDropped(EntityJoinWorldEvent event)
{
Entity e = event.getEntity();
World world = event.getWorld();
if (e instanceof EntityItem)
{
EntityItem eitem = (EntityItem) e;
ItemStack stack = eitem.getEntityItem();
Item item = stack.getItem();
if (item == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
{
BlockPos pos = eitem.getPosition();
Entity entity = ItemEntity.getEntity(stack, world);
entity.setPosition(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
world.spawnEntityInWorld(entity);
ItemEntity.clearEntityData(stack);
eitem.setEntityItemStack(null);
}
}
}
@SubscribeEvent(priority = EventPriority.NORMAL)
public void onEntityRightClick(PlayerInteractEvent.EntityInteract event)
{
EntityPlayer player = event.getEntityPlayer();
if (player instanceof EntityPlayerMP)
{
ItemStack main = player.getHeldItemMainhand();
ItemStack off = player.getHeldItemOffhand();
World world = event.getWorld();
Entity entity = event.getTarget();
BlockPos pos = entity.getPosition();
if (main == null && off == null && player.isSneaking())
{
ItemStack stack = new ItemStack(RegistrationHandler.itemEntity);
if (PickupHandler.canPlayerPickUpEntity(player, entity))
{
if (ItemEntity.storeEntityData(entity, world, stack))
{
entity.setDead();
player.setHeldItem(EnumHand.MAIN_HAND, stack);
event.setCanceled(true);
}
}
}
}
}
}

View File

@ -5,6 +5,7 @@ import net.minecraft.block.state.IBlockState;
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.tileentity.TileEntity;
@ -20,6 +21,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
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;
@ -79,38 +81,36 @@ public class ItemEvents
public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event)
{
EntityPlayer player = event.getEntityPlayer();
ItemStack main = player.getHeldItemMainhand();
ItemStack off = player.getHeldItemOffhand();
World world = event.getWorld();
BlockPos pos = event.getPos();
Block block = world.getBlockState(pos).getBlock();
IBlockState state = world.getBlockState(pos);
if (main == null && off == null && player.isSneaking() && !ForbiddenTileHandler.isForbidden(block))
if (player instanceof EntityPlayerMP)
{
ItemStack stack = new ItemStack(RegistrationHandler.itemTile);
TileEntity te = world.getTileEntity(pos);
if ((CarryOnConfig.settings.pickupAllBlocks ? true : te != null) && (block.getBlockHardness(state, world, pos) != -1 || player.isCreative()))
ItemStack main = player.getHeldItemMainhand();
ItemStack off = player.getHeldItemOffhand();
World world = event.getWorld();
BlockPos pos = event.getPos();
Block block = world.getBlockState(pos).getBlock();
IBlockState state = world.getBlockState(pos);
if (main == null && off == null && player.isSneaking() && !ForbiddenTileHandler.isForbidden(block))
{
double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ);
ItemStack stack = new ItemStack(RegistrationHandler.itemTile);
if (distance < Math.pow(CarryOnConfig.settings.maxDistance, 2))
TileEntity te = world.getTileEntity(pos);
if (PickupHandler.canPlayerPickUpBlock(player, te, world, pos))
{
if (!ItemTile.isLocked(pos, world))
if (ItemTile.storeTileData(te, world, pos, state.getActualState(world, pos), stack))
{
if (ItemTile.storeTileData(te, world, pos, state.getActualState(world, pos), stack))
{
world.removeTileEntity(pos);
world.setBlockToAir(pos);
player.setHeldItem(EnumHand.MAIN_HAND, stack);
event.setUseBlock(Result.DENY);
}
world.removeTileEntity(pos);
world.setBlockToAir(pos);
player.setHeldItem(EnumHand.MAIN_HAND, stack);
event.setUseBlock(Result.DENY);
event.setCanceled(true);
}
}
}
}
}

View File

@ -4,31 +4,45 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import tschipp.carryon.common.config.CarryOnConfig;
public class ForbiddenTileHandler
{
public static final List<String> FORBIDDEN_TILES;
public static List<String> FORBIDDEN_TILES;
public static List<String> FORBIDDEN_ENTITIES;
public static boolean isForbidden(Block block)
{
return FORBIDDEN_TILES.contains(block.getRegistryName().toString());
}
static
public static boolean isForbidden(Entity entity)
{
String[] forbidden = CarryOnConfig.forbiddenTiles.forbiddenTiles;
FORBIDDEN_TILES = new ArrayList<String>();
for(int i = 0; i < forbidden.length; i++)
if (EntityList.getEntityString(entity) != null)
{
if(forbidden[i].contains("*"))
String name = EntityList.getEntityString(entity);
boolean contains = FORBIDDEN_ENTITIES.contains(name);
return contains;
}
return true;
}
public static void initForbiddenTiles()
{
String[] forbidden = CarryOnConfig.blacklist.forbiddenTiles;
FORBIDDEN_TILES = new ArrayList<String>();
for (int i = 0; i < forbidden.length; i++)
{
if (forbidden[i].contains("*"))
{
String modid = forbidden[i].replace("*", "");
for(int k = 0; k < Block.REGISTRY.getKeys().size(); k++)
for (int k = 0; k < Block.REGISTRY.getKeys().size(); k++)
{
if(Block.REGISTRY.getKeys().toArray()[k].toString().contains(modid))
if (Block.REGISTRY.getKeys().toArray()[k].toString().contains(modid))
{
FORBIDDEN_TILES.add(Block.REGISTRY.getKeys().toArray()[k].toString());
}
@ -36,5 +50,25 @@ public class ForbiddenTileHandler
}
FORBIDDEN_TILES.add(forbidden[i]);
}
String[] forbiddenEntity = CarryOnConfig.blacklist.forbiddenEntities;
FORBIDDEN_ENTITIES = new ArrayList<String>();
for (int i = 0; i < forbiddenEntity.length; i++)
{
if (forbiddenEntity[i].contains("*"))
{
String modid = forbiddenEntity[i].replace("*", "");
for (int k = 0; k < EntityList.getEntityNameList().size(); k++)
{
if (EntityList.getEntityNameList().get(k).contains(modid))
{
FORBIDDEN_ENTITIES.add(EntityList.getEntityNameList().get(k));
}
}
}
FORBIDDEN_ENTITIES.add(forbiddenEntity[i]);
}
}
}

View File

@ -4,26 +4,21 @@ import java.util.HashMap;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Level;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.IntHashMap;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tschipp.carryon.CarryOn;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.helper.InvalidConfigException;
import tschipp.carryon.common.helper.StringParser;
@ -43,14 +38,14 @@ public class ModelOverridesHandler
for (int i = 0; i < overrides.length; i++)
{
boolean errored = false;
Object toOverrideObject;
Object overrideObject;
NBTTagCompound tag = new NBTTagCompound();
String currentline = overrides[i];
if (StringUtils.isEmpty(currentline) || !StringUtils.contains(currentline, "->"))
new InvalidConfigException("Missing Override Model at line " + i + " : " + currentline).printException();
new InvalidConfigException("Missing Override Model at line " + i + " : " + currentline).printException();
String[] sa = currentline.split("->");
String toOverride = "";
@ -63,7 +58,7 @@ public class ModelOverridesHandler
catch (ArrayIndexOutOfBoundsException e)
{
errored = true;
new InvalidConfigException("Missing Override Model at line " + i + " : " + currentline).printException();
new InvalidConfigException("Missing Override Model at line " + i + " : " + currentline).printException();
}
if (toOverride.contains("{"))
@ -71,7 +66,7 @@ public class ModelOverridesHandler
if (!toOverride.contains("}"))
{
errored = true;
new InvalidConfigException("Missing } at line " + i + " : " + currentline).printException();
new InvalidConfigException("Missing } at line " + i + " : " + currentline).printException();
}
String nbt = toOverride.substring(toOverride.indexOf("{"));
@ -83,14 +78,35 @@ public class ModelOverridesHandler
catch (NBTException e)
{
errored = true;
new InvalidConfigException("Error while parsing NBT at line " + i + " : " + e.getMessage()).printException();
new InvalidConfigException("Error while parsing NBT at line " + i + " : " + e.getMessage()).printException();
}
}
else if (toOverride.contains("}"))
{
errored = true;
new InvalidConfigException("Missing { at line " + i + " : " + currentline).printException();
new InvalidConfigException("Missing { at line " + i + " : " + currentline).printException();
}
String overridetype = "item";
if (override.contains("("))
{
if (!override.contains(")"))
{
errored = true;
new InvalidConfigException("Missing ) at line " + i + " : " + currentline).printException();
}
overridetype = override.substring(0, override.indexOf(")") + 1);
override =override.replace(overridetype, "");
overridetype = overridetype.replace("(", "");
overridetype = overridetype.replace(")", "");
}
else if (override.contains(")"))
{
errored = true;
new InvalidConfigException("Missing ( at line " + i + " : " + currentline).printException();
}
String modidToOverride = "minecraft";
@ -112,12 +128,10 @@ public class ModelOverridesHandler
if (toOverrideObject != null)
{
overrideObject = StringParser.getItem(override);
if (Block.getBlockFromItem((Item) overrideObject) != Blocks.AIR)
overrideObject = StringParser.getItemStack(override);
else
if (overridetype.equals("block"))
overrideObject = StringParser.getBlockState(override);
else
overrideObject = StringParser.getItemStack(override);
if (overrideObject != null)
{
@ -175,7 +189,7 @@ public class ModelOverridesHandler
}
@SideOnly(Side.CLIENT)
public static IBakedModel getCustomOverrideModel(IBlockState state, NBTTagCompound tag)
public static IBakedModel getCustomOverrideModel(IBlockState state, NBTTagCompound tag, World world, EntityPlayer player)
{
int stateid = Block.getStateId(state);
NBTTagCompound[] keys = new NBTTagCompound[OVERRIDE_OBJECTS.size()];
@ -208,7 +222,7 @@ public class ModelOverridesHandler
if (override instanceof IBlockState)
return Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState((IBlockState) override);
else
return Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel((ItemStack) override);
return Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides((ItemStack) override, world, player);
}
}
}
@ -216,5 +230,39 @@ public class ModelOverridesHandler
return null;
}
public static Object getOverrideObject(IBlockState state, NBTTagCompound tag)
{
int stateid = Block.getStateId(state);
NBTTagCompound[] keys = new NBTTagCompound[OVERRIDE_OBJECTS.size()];
OVERRIDE_OBJECTS.keySet().toArray(keys);
for (NBTTagCompound key : keys)
{
int id = key.getInteger("stateid");
Block block = StringParser.getBlock(key.getString("block"));
if (id == 0 ? block == state.getBlock() : id == stateid)
{
NBTTagCompound toCheckForCompound = key.getCompoundTag("nbttag");
Set<String> kSetToCheck = toCheckForCompound.getKeySet();
Set<String> kSetTile = tag.getKeySet();
boolean flag = true;
if (kSetTile.containsAll(kSetToCheck))
{
for (String skey : kSetToCheck)
{
if (!NBTUtil.areNBTEquals(tag.getTag(skey), toCheckForCompound.getTag(skey), true))
flag = false;
}
if (flag)
{
Object override = OVERRIDE_OBJECTS.get(key);
return override;
}
}
}
}
return null;
}
}

View File

@ -0,0 +1,92 @@
package tschipp.carryon.common.handler;
import javax.annotation.Nullable;
import com.feed_the_beast.ftbl.lib.math.BlockPosContainer;
import com.feed_the_beast.ftbu.api.chunks.BlockInteractionType;
import com.feed_the_beast.ftbu.api_impl.ClaimedChunkStorage;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Loader;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.item.ItemTile;
public class PickupHandler
{
public static boolean canPlayerPickUpBlock(EntityPlayer player, @Nullable TileEntity tile, World world, BlockPos pos)
{
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
player.closeScreen();
if ((block.getBlockHardness(state, world, pos) != -1 || player.isCreative()))
{
double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ);
if (distance < Math.pow(CarryOnConfig.settings.maxDistance, 2))
{
if (!ItemTile.isLocked(pos, world))
{
if (CarryOnConfig.settings.pickupAllBlocks ? true : tile != null)
{
return true && handleFTBUtils((EntityPlayerMP) player, world, pos, state);
}
}
}
}
return false;
}
public static boolean canPlayerPickUpEntity(EntityPlayer player, Entity toPickUp)
{
BlockPos pos = toPickUp.getPosition();
if (!(toPickUp instanceof EntityPlayer) && !ForbiddenTileHandler.isForbidden(toPickUp))
{
if ((CarryOnConfig.settings.pickupHostileMobs ? true : !toPickUp.isCreatureType(EnumCreatureType.MONSTER, false) || player.isCreative()))
{
if ((toPickUp.height <= CarryOnConfig.settings.maxEntityHeight && toPickUp.width <= CarryOnConfig.settings.maxEntityWidth || player.isCreative()))
{
double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ);
if (distance < Math.pow(CarryOnConfig.settings.maxDistance, 2))
{
if (toPickUp instanceof EntityTameable)
{
EntityTameable tame = (EntityTameable) toPickUp;
if (tame.getOwnerId() != null && tame.getOwnerId() != player.getUUID(player.getGameProfile()))
return false;
}
return true;
}
}
}
}
return false;
}
private static boolean handleFTBUtils(EntityPlayerMP player, World world, BlockPos pos, IBlockState state)
{
if (Loader.isModLoaded("ftbu"))
{
BlockPosContainer container = new BlockPosContainer(world, pos, state);
return ClaimedChunkStorage.INSTANCE.canPlayerInteract((EntityPlayerMP) player, EnumHand.MAIN_HAND, container, BlockInteractionType.CNB_BREAK);
}
return true;
}
}

View File

@ -5,38 +5,48 @@ import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import tschipp.carryon.CarryOn;
import tschipp.carryon.client.event.RenderEntityEvents;
import tschipp.carryon.client.event.RenderEvents;
import tschipp.carryon.common.event.ItemEntityEvents;
import tschipp.carryon.common.event.ItemEvents;
import tschipp.carryon.common.item.ItemEntity;
import tschipp.carryon.common.item.ItemTile;
public class RegistrationHandler
{
public static Item itemTile;
public static Item itemEntity;
public static void regItems()
{
itemTile = new ItemTile();
itemEntity = new ItemEntity();
}
public static void regItemRenders()
{
ModelLoader.setCustomModelResourceLocation(itemTile, 0, new ModelResourceLocation(CarryOn.MODID + ":" + "tile", "inventory"));
ModelLoader.setCustomModelResourceLocation(itemEntity, 0, new ModelResourceLocation(CarryOn.MODID + ":" + "tile", "inventory"));
}
public static void regCommonEvents()
{
MinecraftForge.EVENT_BUS.register(new ItemEvents());
MinecraftForge.EVENT_BUS.register(new ItemEntityEvents());
}
public static void regClientEvents()
{
MinecraftForge.EVENT_BUS.register(new RenderEvents());
MinecraftForge.EVENT_BUS.register(new RenderEntityEvents());
}
public static void regOverrideList()
{
ModelOverridesHandler.initOverrides();
ForbiddenTileHandler.initForbiddenTiles();
}
}

View File

@ -0,0 +1,216 @@
package tschipp.carryon.common.item;
import javax.annotation.Nonnull;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
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;
public class ItemEntity extends Item
{
public static final String ENTITY_DATA_KEY = "entityData";
public ItemEntity()
{
this.setUnlocalizedName("entity_item");
this.setRegistryName(CarryOn.MODID, "entity_item");
GameRegistry.register(this);
this.setMaxStackSize(1);
}
@Override
public String getItemStackDisplayName(ItemStack stack)
{
if (hasEntityData(stack))
{
return I18n.translateToLocal(getEntityName(stack));
}
return "";
}
public static boolean hasEntityData(ItemStack stack)
{
if (stack.hasTagCompound())
{
NBTTagCompound tag = stack.getTagCompound();
return tag.hasKey(ENTITY_DATA_KEY) && tag.hasKey("entity");
}
return false;
}
public static boolean storeEntityData(@Nonnull Entity entity, World world, @Nonnull ItemStack stack)
{
if (entity == null)
return false;
if (stack == null)
return false;
NBTTagCompound entityData = new NBTTagCompound();
entityData = entity.writeToNBT(entityData);
String name = EntityList.getEntityString(entity);
NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();
if (tag.hasKey(ENTITY_DATA_KEY))
return false;
tag.setTag(ENTITY_DATA_KEY, entityData);
tag.setString("entity", name);
stack.setTagCompound(tag);
return true;
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
Block block = world.getBlockState(pos).getBlock();
if (hasEntityData(stack))
{
BlockPos finalPos = pos;
if (!block.isReplaceable(world, pos))
{
finalPos = pos.offset(facing);
}
Entity entity = getEntity(stack, world);
if (entity != null)
{
if (!world.isRemote)
{
entity.setPositionAndRotation(finalPos.getX() + 0.5, finalPos.getY(), finalPos.getZ() + 0.5, 180 + player.rotationYawHead, 0.0f);
world.spawnEntityInWorld(entity);
if (entity instanceof EntityLiving)
{
((EntityLiving) entity).playLivingSound();
}
clearEntityData(stack);
player.setHeldItem(hand, null);
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.FAIL;
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)
{
if (hasEntityData(stack))
{
if(getEntity(stack, world) == null)
stack = null;
if (entity instanceof EntityLivingBase)
{
if(entity instanceof EntityPlayer && CarryOnConfig.settings.slownessInCreative ? false : ((EntityPlayer)entity).isCreative())
return;
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 1, potionLevel(stack, world), false, false));
}
}
else
{
stack = null;
}
}
public static void clearEntityData(ItemStack stack)
{
if (stack.hasTagCompound())
{
NBTTagCompound tag = stack.getTagCompound();
tag.removeTag(ENTITY_DATA_KEY);
tag.removeTag("entity");
}
}
public static NBTTagCompound getEntityData(ItemStack stack)
{
if (stack.hasTagCompound())
{
NBTTagCompound tag = stack.getTagCompound();
return tag.getCompoundTag(ENTITY_DATA_KEY);
}
return null;
}
public static Entity getEntity(ItemStack stack, World world)
{
if (world == null)
return null;
String name = getEntityName(stack);
NBTTagCompound e = getEntityData(stack);
Entity entity = EntityList.createEntityByIDFromName(name, world);
if (entity != null)
entity.readFromNBT(e);
return entity;
}
public static String getEntityName(ItemStack stack)
{
if (stack.hasTagCompound())
{
NBTTagCompound tag = stack.getTagCompound();
return tag.getString("entity");
}
return null;
}
public static String getCustomName(ItemStack stack)
{
if (stack.hasTagCompound())
{
NBTTagCompound tag = stack.getTagCompound();
if (tag.hasKey("CustomName") && !tag.getString("CustomName").isEmpty()) {
return tag.toString();
} else {
return tag.toString();
}
}
return null;
}
private int potionLevel(ItemStack stack, World world)
{
Entity e = getEntity(stack, world);
if(e == null)
return 1;
int i = (int)(e.height * e.width);
if (i > 4)
i = 4;
if (!CarryOnConfig.settings.heavyEntities)
i = 1;
return i;
}
}

View File

@ -31,6 +31,7 @@ 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.ModelOverridesHandler;
public class ItemTile extends Item
{
@ -52,9 +53,25 @@ public class ItemTile extends Item
{
if (hasTileData(stack))
{
ItemStack contained = getItemStack(stack);
if (contained != null)
return contained.getDisplayName();
NBTTagCompound nbt = getTileData(stack);
IBlockState state = getBlockState(stack);
if (ModelOverridesHandler.hasCustomOverrideModel(state, nbt))
{
Object override = ModelOverridesHandler.getOverrideObject(state, nbt);
if (override instanceof ItemStack)
return ((ItemStack) override).getDisplayName();
else
{
IBlockState ostate = (IBlockState) override;
ItemStack itemstack = new ItemStack(ostate.getBlock().getItemDropped(ostate, this.itemRand, 0), 1, state.getBlock().damageDropped(ostate));
return itemstack.getDisplayName();
}
}
ItemStack istack = getItemStack(stack);
if (istack != null)
return istack.getDisplayName();
}
}
@ -142,6 +159,9 @@ public class ItemTile extends Item
{
if (entity instanceof EntityLivingBase)
{
if (entity instanceof EntityPlayer && CarryOnConfig.settings.slownessInCreative ? false : ((EntityPlayer) entity).isCreative())
return;
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 1, potionLevel(stack), false, false));
}
}
@ -163,9 +183,6 @@ public class ItemTile extends Item
public static boolean storeTileData(@Nullable TileEntity tile, World world, BlockPos pos, IBlockState state, ItemStack stack)
{
if (CarryOnConfig.settings.pickupAllBlocks ? false : tile == null)
return false;
if (stack == null)
return false;
@ -179,7 +196,7 @@ public class ItemTile extends Item
tag.setTag(TILE_DATA_KEY, chest);
ItemStack drop = state.getBlock().getItem(world, pos, state);
ItemStack drop = new ItemStack(state.getBlock().getItemDropped(state, itemRand, 0), 1, state.getBlock().damageDropped(state));
tag.setString("block", state.getBlock().getRegistryName().toString());
Item item = Item.getItemFromBlock(state.getBlock());

View File

@ -1,5 +1,10 @@
carryon.category.settings=Settings
carryon.category.forbiddentiles=Forbidden Tile Entities
carryon.category.blacklist=Blacklist
carryon.category.modeloverrides=Model Overrides (Advanced)
carryon.category.custompickupconditions=Custom Pickup Conditions (Advanced)
carryon.general.modeloverrides.modeloverrides=Model Overrides
carryon.general.modeloverrides.modeloverrides=Model Overrides
carryon.general.blacklist.forbiddenentities=Entities that the Player cannot pick up
carryon.general.blacklist.forbiddentiles=Blocks that the Player cannot pick up
carryon.category.custompickupconditions.custompickupconditionsblocks=Custom Block Pickup Conditions
carryon.category.custompickupconditions.custompickupconditionsentities=Custom Entity Pickup Conditions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 B

After

Width:  |  Height:  |  Size: 198 B

View File

@ -2,13 +2,13 @@
{
"modid" : "carryon",
"name" : "Carry On",
"version" : "1.1.1", "mcversion" : "1.10.2",
"version" : "1.2", "mcversion" : "1.10.2",
"url" : "",
"credits" : "Tschipp, Purplicious_Cow, cy4n",
"authorList" : ["Tschipp, Purplicious_Cow, cy4n"],
"description": "Carry On is a simple mod that improves game interaction by allowing players to pick up, carry, and place single block Tile Entities using only their empty hands.",
"logoFile" : "assets/carryon/logo.png",
"updateUrl" : "",
"updateUrl" : "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/5115328bf7c35d5c5cea64bdb58becd2ca17fcac/update.json",
"parent" : "",
"dependencies": [],
"screenshots": []