Update to 1.2
This commit is contained in:
commit
10ea3ae8ea
|
|
@ -1,4 +1,2 @@
|
|||
# CarryOn
|
||||
Carry On mod for Minecraft
|
||||
|
||||
Download here: https://minecraft.curseforge.com/projects/carry-on
|
||||
# Carry On [](https://minecraft.curseforge.com/projects/carry-on) [](https://minecraft.curseforge.com/projects/carry-on)
|
||||
|
|
|
|||
23
build.gradle
23
build.gradle
|
|
@ -2,11 +2,16 @@ buildscript {
|
|||
repositories {
|
||||
jcenter()
|
||||
maven { url = "http://files.minecraftforge.net/maven" }
|
||||
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-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 {
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,274 @@
|
|||
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().player.getHeldItemMainhand();
|
||||
if (!stack.isEmpty() && 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().player;
|
||||
if (player != null)
|
||||
{
|
||||
ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND);
|
||||
if (inventory && !stack.isEmpty() && 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()[8];
|
||||
field.setAccessible(true);
|
||||
ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand();
|
||||
if (!stack.isEmpty() && 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().world;
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
AbstractClientPlayer aplayer = (AbstractClientPlayer) player;
|
||||
ItemStack stack = player.getHeldItemMainhand();
|
||||
int perspective = Minecraft.getMinecraft().gameSettings.thirdPersonView;
|
||||
float partialticks = event.getPartialTicks();
|
||||
|
||||
|
||||
if (!stack.isEmpty() && 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().world;
|
||||
EntityPlayer player = event.getEntityPlayer();
|
||||
ModelPlayer modelPlayer = event.getRenderer().getMainModel();
|
||||
EntityPlayerSP clientPlayer = Minecraft.getMinecraft().player;
|
||||
ItemStack stack = player.getHeldItemMainhand();
|
||||
float partialticks = event.getPartialRenderTick();
|
||||
if (!stack.isEmpty() && 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().world.isDaytime()) {
|
||||
i = entityIn.getBrightnessForRender();
|
||||
} 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_);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.isEmpty() ? 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, 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.isEmpty() ? stack : tileStack, model);
|
||||
}
|
||||
else
|
||||
Minecraft.getMinecraft().getRenderItem().renderItem(tileStack.isEmpty() ? 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.isEmpty() ? 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,6 +201,7 @@ public class RenderEvents
|
|||
ModelPlayer modelPlayer = event.getRenderer().getMainModel();
|
||||
EntityPlayerSP clientPlayer = Minecraft.getMinecraft().player;
|
||||
ItemStack stack = player.getHeldItemMainhand();
|
||||
float partialticks = event.getPartialRenderTick();
|
||||
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack))
|
||||
{
|
||||
Block block = ItemTile.getBlock(stack);
|
||||
|
|
@ -192,9 +213,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);
|
||||
|
|
@ -214,18 +243,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.isEmpty() ? stack : tileItem, model);
|
||||
|
||||
IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, world, player) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(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.isEmpty() ? stack : tileItem, model);
|
||||
}
|
||||
else
|
||||
Minecraft.getMinecraft().getRenderItem().renderItem(tileItem.isEmpty() ? stack : tileItem, model);
|
||||
GlStateManager.scale(1, 1, 1);
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
else
|
||||
{
|
||||
modelPlayer.bipedLeftArm.isHidden = false;
|
||||
modelPlayer.bipedRightArm.isHidden = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -236,74 +271,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().player;
|
||||
|
||||
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().player;
|
||||
|
||||
ResourceLocation skinLoc = DefaultPlayerSkin.getDefaultSkin(player.getPersistentID());
|
||||
|
||||
ModelRenderer fakeLeftArm = new ModelRenderer(model, 32, 48);
|
||||
ModelRenderer fakeRightArm = new ModelRenderer(model, 40, 16);
|
||||
|
||||
if (!stack.isEmpty() && 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.isEmpty() && (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.6F;
|
||||
fakeLeftArm.rotateAngleX = -1.6F;
|
||||
}
|
||||
}
|
||||
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.isEmpty() || (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.6F;
|
||||
fakeLeftArm.rotateAngleX = -1.6F;
|
||||
}
|
||||
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.isEmpty() || stack.getItem() != RegistrationHandler.itemTile || !ItemTile.hasTileData(stack))
|
||||
{
|
||||
model.bipedLeftArm.isHidden = false;
|
||||
model.bipedRightArm.isHidden = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -326,4 +393,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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,16 @@ 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!")
|
||||
public static Configs.ModelOverrides modelOverrides = new Configs.ModelOverrides();
|
||||
|
||||
@Config.LangKey(CarryOn.MODID)
|
||||
@Config.Comment("Custom Pickup Conditions for certain blocks. ONLY WORKS WHEN GAMESTAGES IS INSTALLED! Advanced Users Only!")
|
||||
public static Configs.CustomPickupConditions customPickupConditions = new Configs.CustomPickupConditions();
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public static class EventHandler {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
@Config.RequiresMcRestart()
|
||||
@Comment("Tile Entities that cannot be picked up")
|
||||
|
|
@ -30,6 +48,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:*",
|
||||
|
|
@ -53,6 +78,17 @@ public class Configs {
|
|||
"embers:inferno_forge",
|
||||
"storagedrawers:framingtable",
|
||||
};
|
||||
|
||||
@Config.RequiresMcRestart()
|
||||
@Comment("Entities that cannot be picked up")
|
||||
public String[] forbiddenEntities = new String[]
|
||||
{
|
||||
"minecraft:ender_crystal",
|
||||
"minecraft:ender_dragon",
|
||||
"minecraft:ghast",
|
||||
"minecraft:shulker",
|
||||
"animania:textures/entity/pigs/hamster_tarou.png"
|
||||
};
|
||||
}
|
||||
|
||||
public static class ModelOverrides
|
||||
|
|
@ -62,7 +98,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",
|
||||
|
|
@ -100,5 +146,24 @@ public class Configs {
|
|||
"storagedrawers:basicdrawers;4{Mat:\"dark_oak\"}->storagedrawers:basicdrawers;4{material:\"dark_oak\"}"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class CustomPickupConditions
|
||||
{
|
||||
@Config.RequiresMcRestart()
|
||||
@Comment("Custom Pickup Conditions for Blocks")
|
||||
public String[] customPickupConditionsBlocks = new String[]
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
@Config.RequiresMcRestart()
|
||||
@Comment("Custom Pickup Conditions for Entities")
|
||||
public String[] customPickupConditionsEntities = new String[]
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.isEmpty() && 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.getItem();
|
||||
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.spawnEntity(entity);
|
||||
|
||||
ItemEntity.clearEntityData(stack);
|
||||
eitem.setItem(ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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.isEmpty() && off.isEmpty() && 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.isEmpty() && off.isEmpty() && 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.isEmpty() && off.isEmpty() && 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
package tschipp.carryon.common.handler;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import tschipp.carryon.common.config.CarryOnConfig;
|
||||
import tschipp.carryon.common.helper.InvalidConfigException;
|
||||
|
||||
public class CustomPickupOverrideHandler
|
||||
{
|
||||
|
||||
public static HashMap<String, String> PICKUP_CONDITIONS = new HashMap<String, String>();
|
||||
public static HashMap<String, String> PICKUP_CONDITIONS_ENTITIES = new HashMap<String, String>();
|
||||
|
||||
public static void initPickupOverrides()
|
||||
{
|
||||
if (Loader.isModLoaded("gamestages"))
|
||||
{
|
||||
|
||||
String[] conditions = CarryOnConfig.customPickupConditions.customPickupConditionsBlocks;
|
||||
|
||||
for (int i = 0; i < conditions.length; i++)
|
||||
{
|
||||
String line = conditions[i];
|
||||
|
||||
if (!line.contains("(") || !line.contains(")"))
|
||||
new InvalidConfigException("Invalid Condition at line " + i + ": " + line).printException();
|
||||
|
||||
String condition = line.substring(line.indexOf("("));
|
||||
String blockname = line.replace(condition, "");
|
||||
condition = condition.replace("(", "");
|
||||
condition = condition.replace(")", "");
|
||||
|
||||
if (blockname.contains("*"))
|
||||
{
|
||||
String modid = blockname.replace("*", "");
|
||||
for (int k = 0; k < Block.REGISTRY.getKeys().size(); k++)
|
||||
{
|
||||
if (Block.REGISTRY.getKeys().toArray()[k].toString().contains(modid))
|
||||
{
|
||||
PICKUP_CONDITIONS.put(Block.REGISTRY.getKeys().toArray()[k].toString() + ";any", condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!blockname.contains(";"))
|
||||
blockname = blockname + ";any";
|
||||
|
||||
PICKUP_CONDITIONS.put(blockname, condition);
|
||||
}
|
||||
}
|
||||
|
||||
String[] entityConditions = CarryOnConfig.customPickupConditions.customPickupConditionsEntities;
|
||||
|
||||
for (int i = 0; i < entityConditions.length; i++)
|
||||
{
|
||||
String line = entityConditions[i];
|
||||
|
||||
if (!line.contains("(") || !line.contains(")"))
|
||||
new InvalidConfigException("Invalid Condition at line " + i + ": " + line).printException();
|
||||
|
||||
String condition = line.substring(line.indexOf("("));
|
||||
String entityname = line.replace(condition, "");
|
||||
condition = condition.replace("(", "");
|
||||
condition = condition.replace(")", "");
|
||||
|
||||
PICKUP_CONDITIONS_ENTITIES.put(entityname, condition);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasSpecialPickupConditions(IBlockState state)
|
||||
{
|
||||
if (!Loader.isModLoaded("gamestages"))
|
||||
return false;
|
||||
|
||||
String block = state.getBlock().getRegistryName().toString();
|
||||
String meta = "" + state.getBlock().getMetaFromState(state);
|
||||
|
||||
boolean absolute = PICKUP_CONDITIONS.containsKey(block + ";" + meta);
|
||||
boolean any = PICKUP_CONDITIONS.containsKey(block + ";any");
|
||||
|
||||
return absolute || any;
|
||||
}
|
||||
|
||||
public static String getPickupCondition(IBlockState state)
|
||||
{
|
||||
String block = state.getBlock().getRegistryName().toString();
|
||||
String meta = "" + state.getBlock().getMetaFromState(state);
|
||||
|
||||
String absolute = PICKUP_CONDITIONS.get(block + ";" + meta);
|
||||
String any = PICKUP_CONDITIONS.get(block + ";any");
|
||||
|
||||
if (absolute != null)
|
||||
return absolute;
|
||||
else
|
||||
return any;
|
||||
}
|
||||
|
||||
public static boolean hasSpecialPickupConditions(Entity entity)
|
||||
{
|
||||
if (!Loader.isModLoaded("gamestages"))
|
||||
return false;
|
||||
|
||||
String entityname = EntityList.getKey(entity).toString();
|
||||
boolean condition = PICKUP_CONDITIONS_ENTITIES.containsKey(entityname);
|
||||
|
||||
return condition;
|
||||
}
|
||||
|
||||
public static String getPickupCondition(Entity entity)
|
||||
{
|
||||
String entityname = EntityList.getKey(entity).toString();
|
||||
String condition = PICKUP_CONDITIONS_ENTITIES.get(entityname);
|
||||
|
||||
return condition;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.getKey(entity) != null)
|
||||
{
|
||||
if(forbidden[i].contains("*"))
|
||||
String name = EntityList.getKey(entity).toString();
|
||||
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 < ForgeRegistries.ENTITIES.getKeys().size(); k++)
|
||||
{
|
||||
if (ForgeRegistries.ENTITIES.getKeys().toArray()[k].toString().contains(modid))
|
||||
{
|
||||
FORBIDDEN_ENTITIES.add(ForgeRegistries.ENTITIES.getKeys().toArray()[k].toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
FORBIDDEN_ENTITIES.add(forbiddenEntity[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,23 +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.world.World;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
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;
|
||||
|
|
@ -40,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 = "";
|
||||
|
|
@ -60,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("{"))
|
||||
|
|
@ -68,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("{"));
|
||||
|
|
@ -80,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";
|
||||
|
|
@ -110,12 +129,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)
|
||||
{
|
||||
|
|
@ -173,7 +190,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()];
|
||||
|
|
@ -206,7 +223,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -214,5 +231,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
112
src/main/java/tschipp/carryon/common/handler/PickupHandler.java
Normal file
112
src/main/java/tschipp/carryon/common/handler/PickupHandler.java
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
package tschipp.carryon.common.handler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.feed_the_beast.ftbl.lib.math.BlockPosContainer;
|
||||
import com.feed_the_beast.ftbu.FTBUPermissions;
|
||||
import com.feed_the_beast.ftbu.api.chunks.BlockInteractionType;
|
||||
import com.feed_the_beast.ftbu.api_impl.ClaimedChunkStorage;
|
||||
|
||||
import net.darkhax.gamestages.capabilities.PlayerDataHandler;
|
||||
import net.darkhax.gamestages.capabilities.PlayerDataHandler.IStageData;
|
||||
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.inventory.Container;
|
||||
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 (CustomPickupOverrideHandler.hasSpecialPickupConditions(state))
|
||||
{
|
||||
IStageData stageData = PlayerDataHandler.getStageData(player);
|
||||
String condition = CustomPickupOverrideHandler.getPickupCondition(state);
|
||||
if (stageData.hasUnlockedStage(condition))
|
||||
return true && handleFTBUtils((EntityPlayerMP) player, world, pos, state);
|
||||
|
||||
}
|
||||
else 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;
|
||||
}
|
||||
|
||||
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp))
|
||||
{
|
||||
IStageData stageData = PlayerDataHandler.getStageData(player);
|
||||
String condition = CustomPickupOverrideHandler.getPickupCondition(toPickUp);
|
||||
if (stageData.hasUnlockedStage(condition))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,38 +5,49 @@ 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();
|
||||
CustomPickupOverrideHandler.initPickupOverrides();
|
||||
ForbiddenTileHandler.initForbiddenTiles();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
218
src/main/java/tschipp/carryon/common/item/ItemEntity.java
Normal file
218
src/main/java/tschipp/carryon/common/item/ItemEntity.java
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
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.ForgeRegistries;
|
||||
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");
|
||||
ForgeRegistries.ITEMS.register(this);
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
if (hasEntityData(stack))
|
||||
{
|
||||
return I18n.translateToLocal("entity."+EntityList.getTranslationName(new ResourceLocation(getEntityName(stack))) + ".name");
|
||||
}
|
||||
|
||||
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, ItemStack stack)
|
||||
{
|
||||
if (entity == null)
|
||||
return false;
|
||||
|
||||
if (stack.isEmpty())
|
||||
return false;
|
||||
|
||||
NBTTagCompound entityData = new NBTTagCompound();
|
||||
entityData = entity.writeToNBT(entityData);
|
||||
|
||||
String name = EntityList.getKey(entity).toString();
|
||||
|
||||
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(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
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.spawnEntity(entity);
|
||||
if (entity instanceof EntityLiving)
|
||||
{
|
||||
((EntityLiving) entity).playLivingSound();
|
||||
}
|
||||
clearEntityData(stack);
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
}
|
||||
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 = ItemStack.EMPTY;
|
||||
|
||||
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 = ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
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(new ResourceLocation(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;
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
|||
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
|
||||
{
|
||||
|
|
@ -51,6 +52,22 @@ public class ItemTile extends Item
|
|||
{
|
||||
if (hasTileData(stack))
|
||||
{
|
||||
IBlockState state = getBlockState(stack);
|
||||
NBTTagCompound nbt = getTileData(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();
|
||||
}
|
||||
}
|
||||
|
||||
return getItemStack(stack).getDisplayName();
|
||||
}
|
||||
|
||||
|
|
@ -137,6 +154,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));
|
||||
}
|
||||
}
|
||||
|
|
@ -158,9 +178,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.isEmpty())
|
||||
return false;
|
||||
|
||||
|
|
@ -174,7 +191,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());
|
||||
|
|
|
|||
|
|
@ -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 |
|
|
@ -2,13 +2,13 @@
|
|||
{
|
||||
"modid" : "carryon",
|
||||
"name" : "Carry On",
|
||||
"version" : "1.1.1", "mcversion" : "1.12",
|
||||
"version" : "1.2", "mcversion" : "1.12",
|
||||
"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": []
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user