Scripting Part 1

This commit is contained in:
Tschipp 2017-10-01 19:24:37 +02:00
commit 275cf81593
15 changed files with 1530 additions and 218 deletions

0
carryon-scripts Normal file
View File

View File

@ -1,8 +1,11 @@
package tschipp.carryon;
import java.io.File;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventHandler;
@ -15,6 +18,7 @@ import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import tschipp.carryon.common.CommonProxy;
import tschipp.carryon.common.command.CommandCarryOn;
import tschipp.carryon.common.command.CommandCarryOnReload;
@EventBusSubscriber
@Mod(modid = CarryOn.MODID, name = CarryOn.NAME, version = CarryOn.VERSION, guiFactory = "tschipp.carryon.client.gui.GuiFactoryCarryOn", dependencies = "required-after:forge@[13.20.1.2386,)", updateJSON = CarryOn.UPDATE_JSON)
@ -28,21 +32,22 @@ public class CarryOn {
public static CarryOn instance;
public static final String MODID = "carryon";
public static final String VERSION = "1.5.1";
public static final String VERSION = "1.5.1_PRE";
public static final String NAME = "Carry On";
public static final String UPDATE_JSON = "https://gist.githubusercontent.com/Tschipp/dccadee7c90d7a34e6e76a35d9d6fa2e/raw/";
public static final Logger LOGGER = LogManager.getFormatterLogger("CarryOn");
public static File CONFIGURATION_FILE;
public static SimpleNetworkWrapper network;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
public void preInit(FMLPreInitializationEvent event){
CarryOn.proxy.preInit(event);
}
@EventHandler
public void init(FMLInitializationEvent event) {
CarryOn.proxy.init(event);
CarryOn.proxy.init(event);
}
@EventHandler
@ -54,6 +59,17 @@ public class CarryOn {
public void serverLoad(FMLServerStartingEvent event)
{
event.registerServerCommand(new CommandCarryOn());
event.registerServerCommand(new CommandCarryOnReload());
}
public static File getMcDir()
{
if (FMLCommonHandler.instance().getMinecraftServerInstance() != null && FMLCommonHandler.instance().getMinecraftServerInstance().isDedicatedServer())
{
return new File(".");
}
return Minecraft.getMinecraft().mcDataDir;
}
}

View File

@ -2,23 +2,24 @@ package tschipp.carryon.client.event;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.MouseEvent;
@ -29,12 +30,13 @@ 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.helper.ScriptParseHelper;
import tschipp.carryon.common.item.ItemEntity;
import tschipp.carryon.common.item.ItemTile;
import tschipp.carryon.common.scripting.CarryOnOverride;
import tschipp.carryon.common.scripting.ScriptChecker;
public class RenderEntityEvents
{
/*
* Prevents the Player from scrolling
*/
@ -42,16 +44,18 @@ public class RenderEntityEvents
@SubscribeEvent
public void onScroll(MouseEvent event) throws IllegalArgumentException, IllegalAccessException
{
if (event.getDwheel() > 0 || event.getDwheel() < 0)
if (event.getDwheel() > 0 || event.getDwheel() < 0 || Minecraft.getMinecraft().gameSettings.keyBindPickBlock.isPressed())
{
ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand();
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity)
{
if (ItemEntity.hasEntityData(stack))
{
event.setCanceled(true);
}
}
}
}
/*
@ -65,9 +69,11 @@ public class RenderEntityEvents
{
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);
@ -89,6 +95,7 @@ public class RenderEntityEvents
field.setAccessible(true);
ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand();
EntityPlayer player = Minecraft.getMinecraft().player;
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
{
if (settings.keyBindDrop.isPressed())
@ -106,13 +113,14 @@ public class RenderEntityEvents
field.set(keyBind, false);
}
}
}
int current = player.inventory.currentItem;
if (player.getEntityData().hasKey("carrySlot") ? player.getEntityData().getInteger("carrySlot") != current : false)
{
player.inventory.currentItem = player.getEntityData().getInteger("carrySlot");
}
}
/*
@ -122,23 +130,21 @@ public class RenderEntityEvents
@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;
double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialticks;
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialticks;
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialticks;
entity.setPosition(d0, d1, d2);
entity.rotationYaw = 0.0f;
@ -147,8 +153,6 @@ public class RenderEntityEvents
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);
@ -159,13 +163,43 @@ public class RenderEntityEvents
{
RenderHelper.enableStandardItemLighting();
Minecraft.getMinecraft().getRenderManager().setRenderShadow(false);
Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false);
Minecraft.getMinecraft().getRenderManager().setRenderShadow(true);
CarryOnOverride carryOverride = ScriptChecker.inspectEntity(entity);
if (carryOverride != null)
{
double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation());
double[] rotation = ScriptParseHelper.getXYZArray(carryOverride.getRenderRotation());
double[] scale = ScriptParseHelper.getScale(carryOverride.getRenderScale());
String entityname = carryOverride.getRenderNameEntity();
if (entityname != null)
{
Entity newEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entityname), world);
if (newEntity != null)
{
NBTTagCompound nbttag = carryOverride.getRenderNBT();
if (nbttag != null)
newEntity.readFromNBT(nbttag);
entity = newEntity;
entity.setPosition(d0, d1, d2);
entity.rotationYaw = 0.0f;
entity.prevRotationYaw = 0.0f;
entity.setRotationYawHead(0.0f);
}
}
GlStateManager.translate(translation[0], translation[1], translation[2]);
GlStateManager.rotate((float) rotation[0], 1, 0, 0);
GlStateManager.rotate((float) rotation[1], 0, 1, 0);
GlStateManager.rotate((float) rotation[2], 0, 0, 1);
GlStateManager.scale(scale[0], scale[1], scale[2]);
}
this.renderEntityStatic(entity);
Minecraft.getMinecraft().getRenderManager().setRenderShadow(true);
}
GlStateManager.disableAlpha();
GlStateManager.scale(1, 1, 1);
GlStateManager.popMatrix();
@ -176,11 +210,75 @@ public class RenderEntityEvents
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
if (perspective == 0)
{
event.setCanceled(true);
}
}
}
}
@SideOnly(Side.CLIENT)
private void renderEntityStatic(Entity entity)
{
if (entity.ticksExisted == 0)
{
entity.lastTickPosX = entity.posX;
entity.lastTickPosY = entity.posY;
entity.lastTickPosZ = entity.posZ;
}
float f = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw);
int i = this.getBrightnessForRender(entity, Minecraft.getMinecraft().player);
if (entity.isBurning())
{
i = 15728880;
}
int j = i % 65536;
int k = i / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j, k);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.setLightmapDisabled(false);
Minecraft.getMinecraft().getRenderManager().doRenderEntity(entity, 0.0D, 0.0D, 0.0D, f, 0.0F, true);
this.setLightmapDisabled(true);
}
@SideOnly(Side.CLIENT)
private int getBrightnessForRender(Entity entity, EntityPlayer player)
{
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(MathHelper.floor(player.posX), 0, MathHelper.floor(player.posZ));
if (entity.world.isBlockLoaded(blockpos$mutableblockpos))
{
blockpos$mutableblockpos.setY(MathHelper.floor(player.posY + entity.getEyeHeight()));
return entity.world.getCombinedLight(blockpos$mutableblockpos, 0);
}
else
{
return 0;
}
}
@SideOnly(Side.CLIENT)
private void setLightmapDisabled(boolean disabled)
{
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
if (disabled)
{
GlStateManager.disableTexture2D();
}
else
{
GlStateManager.enableTexture2D();
}
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
/*
@ -192,27 +290,25 @@ public class RenderEntityEvents
{
World world = Minecraft.getMinecraft().world;
EntityPlayer player = event.getEntityPlayer();
ModelPlayer modelPlayer = event.getRenderer().getMainModel();
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.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialticks);
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 d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialticks;
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialticks;
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * 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 c0 = clientPlayer.lastTickPosX + (clientPlayer.posX - clientPlayer.lastTickPosX) * partialticks;
double c1 = clientPlayer.lastTickPosY + (clientPlayer.posY - clientPlayer.lastTickPosY) * partialticks;
double c2 = clientPlayer.lastTickPosZ + (clientPlayer.posZ - clientPlayer.lastTickPosZ) * partialticks;
double xOffset = d0 - c0;
double yOffset = d1 - c1;
@ -231,21 +327,52 @@ public class RenderEntityEvents
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));
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);
CarryOnOverride carryOverride = ScriptChecker.inspectEntity(entity);
if (carryOverride != null)
{
double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation());
double[] rot = ScriptParseHelper.getXYZArray(carryOverride.getRenderRotation());
double[] scale = ScriptParseHelper.getScale(carryOverride.getRenderScale());
String entityname = carryOverride.getRenderNameEntity();
if (entityname != null)
{
Entity newEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entityname), world);
if (newEntity != null)
{
NBTTagCompound nbttag = carryOverride.getRenderNBT();
if (nbttag != null)
newEntity.readFromNBT(nbttag);
entity = newEntity;
entity.setPosition(d0, d1, d2);
entity.rotationYaw = 0.0f;
entity.prevRotationYaw = 0.0f;
entity.setRotationYawHead(0.0f);
}
}
GlStateManager.translate(translation[0], translation[1], translation[2]);
GlStateManager.rotate((float) rot[0], 1, 0, 0);
GlStateManager.rotate((float) rot[1], 0, 1, 0);
GlStateManager.rotate((float) rot[2], 0, 0, 1);
GlStateManager.scale(scale[0], scale[1], scale[2]);
}
Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false);
Minecraft.getMinecraft().getRenderManager().setRenderShadow(true);
GlStateManager.scale(1, 1, 1);
GlStateManager.popMatrix();
}
}
}
}

View File

@ -2,7 +2,6 @@ package tschipp.carryon.client.event;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@ -13,6 +12,7 @@ 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.block.model.IBakedModel;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
@ -20,8 +20,8 @@ import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EnumPlayerModelParts;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -29,6 +29,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.MouseEvent;
@ -45,12 +46,21 @@ import tschipp.carryon.client.keybinds.CarryOnKeybinds;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.handler.ModelOverridesHandler;
import tschipp.carryon.common.handler.RegistrationHandler;
import tschipp.carryon.common.helper.ScriptParseHelper;
import tschipp.carryon.common.helper.StringParser;
import tschipp.carryon.common.item.ItemEntity;
import tschipp.carryon.common.item.ItemTile;
import tschipp.carryon.common.scripting.CarryOnOverride;
import tschipp.carryon.common.scripting.ScriptChecker;
import tschipp.carryon.network.server.SyncKeybindPacket;
public class RenderEvents
{
private static boolean initModels;
private ModelRenderer fakeLeftArm;
private ModelRenderer fakeRightArm;
private ModelRenderer fakeLeftArmwear;
private ModelRenderer fakeRightArmwear;
/*
* Prevents the Player from scrolling
@ -59,16 +69,18 @@ public class RenderEvents
@SubscribeEvent
public void onScroll(MouseEvent event)
{
if (event.getDwheel() > 0 || event.getDwheel() < 0)
if (event.getDwheel() > 0 || event.getDwheel() < 0 || Minecraft.getMinecraft().gameSettings.keyBindPickBlock.isPressed())
{
ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand();
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile)
{
if (ItemTile.hasTileData(stack))
{
event.setCanceled(true);
}
}
}
}
@SubscribeEvent
@ -76,9 +88,9 @@ public class RenderEvents
public void onPlayerTick(PlayerTickEvent event) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
EntityPlayer player = event.player;
if (player != null && event.side == Side.CLIENT)
{
boolean keyPressed = CarryOnKeybinds.carryKey.isKeyDown();
boolean playerKeyPressed = CarryOnKeybinds.isKeyPressed(player);
@ -92,8 +104,6 @@ public class RenderEvents
CarryOnKeybinds.setKeyPressed(player, false);
CarryOn.network.sendToServer(new SyncKeybindPacket(false));
}
}
}
@ -108,9 +118,11 @@ public class RenderEvents
{
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.itemTile && ItemTile.hasTileData(stack))
{
event.setCanceled(true);
@ -132,6 +144,7 @@ public class RenderEvents
field.setAccessible(true);
ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand();
EntityPlayer player = Minecraft.getMinecraft().player;
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack))
{
if (settings.keyBindDrop.isPressed())
@ -149,16 +162,14 @@ public class RenderEvents
field.set(keyBind, false);
}
}
}
int current = player.inventory.currentItem;
if(player.getEntityData().hasKey("carrySlot") ? player.getEntityData().getInteger("carrySlot") != current : false)
if (player.getEntityData().hasKey("carrySlot") ? player.getEntityData().getInteger("carrySlot") != current : false)
{
player.inventory.currentItem = player.getEntityData().getInteger("carrySlot");
}
}
/*
@ -177,7 +188,6 @@ public class RenderEvents
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack))
{
Block block = ItemTile.getBlock(stack);
BlockPos pos = player.getPosition();
NBTTagCompound tag = ItemTile.getTileData(stack);
IBlockState state = ItemTile.getBlockState(stack);
ItemStack tileStack = ItemTile.getItemStack(stack);
@ -192,29 +202,73 @@ public class RenderEvents
GlStateManager.rotate(-8, 1f, 0, 0);
}
else
{
GlStateManager.rotate(8, 1f, 0, 0);
}
if (perspective == 0)
{
IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, world, player) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileStack, world, player);
CarryOnOverride carryOverride = ScriptChecker.inspectBlock(state, world, player.getPosition(), tag);
if (carryOverride != null)
{
double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation());
double[] rotation = ScriptParseHelper.getXYZArray(carryOverride.getRenderRotation());
double[] scale = ScriptParseHelper.getScale(carryOverride.getRenderScale());
Block b = StringParser.getBlock(carryOverride.getRenderNameBlock());
if (b != null)
{
ItemStack s = new ItemStack(b, 1, carryOverride.getRenderMeta());
s.setTagCompound(carryOverride.getRenderNBT());
model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(s, world, player);
}
GlStateManager.translate(translation[0], translation[1], translation[2]);
GlStateManager.rotate((float) rotation[0], 1, 0, 0);
GlStateManager.rotate((float) rotation[1], 0, 1, 0);
GlStateManager.rotate((float) rotation[2], 0, 0, 1);
GlStateManager.scale(scale[0], scale[1], scale[2]);
}
int i = this.getBrightnessForRender(Minecraft.getMinecraft().player);
int j = i % 65536;
int k = i / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j, k);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.setLightmapDisabled(false);
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);
}
this.setLightmapDisabled(true);
}
GlStateManager.scale(1, 1, 1);
GlStateManager.popMatrix();
if (perspective == 0)
{
event.setCanceled(true);
}
}
else
{
@ -227,10 +281,45 @@ public class RenderEvents
ModelPlayer modelPlayer = renderPlayer.getMainModel();
modelPlayer.bipedLeftArm.isHidden = false;
modelPlayer.bipedRightArm.isHidden = false;
modelPlayer.bipedLeftArmwear.isHidden = false;
modelPlayer.bipedRightArmwear.isHidden = false;
}
}
}
@SideOnly(Side.CLIENT)
private int getBrightnessForRender(EntityPlayer player)
{
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(MathHelper.floor(player.posX), 0, MathHelper.floor(player.posZ));
if (player.world.isBlockLoaded(blockpos$mutableblockpos))
{
blockpos$mutableblockpos.setY(MathHelper.floor(player.posY + player.getEyeHeight()));
return player.world.getCombinedLight(blockpos$mutableblockpos, 0);
}
else
{
return 0;
}
}
@SideOnly(Side.CLIENT)
private void setLightmapDisabled(boolean disabled)
{
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
if (disabled)
{
GlStateManager.disableTexture2D();
}
else
{
GlStateManager.enableTexture2D();
}
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
/*
* Renders the Block in Third Person
*/
@ -240,28 +329,26 @@ public class RenderEvents
{
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.itemTile && ItemTile.hasTileData(stack))
{
Block block = ItemTile.getBlock(stack);
IBlockState state = ItemTile.getBlockState(stack);
NBTTagCompound tag = ItemTile.getTileData(stack);
ItemStack tileItem = ItemTile.getItemStack(stack);
float rotation = -(player.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialticks);
int perspective = Minecraft.getMinecraft().gameSettings.thirdPersonView;
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 d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialticks;
double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialticks;
double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * 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 c0 = clientPlayer.lastTickPosX + (clientPlayer.posX - clientPlayer.lastTickPosX) * partialticks;
double c1 = clientPlayer.lastTickPosY + (clientPlayer.posY - clientPlayer.lastTickPosY) * partialticks;
double c2 = clientPlayer.lastTickPosZ + (clientPlayer.posZ - clientPlayer.lastTickPosZ) * partialticks;
double xOffset = d0 - c0;
double yOffset = d1 - c1;
@ -283,27 +370,55 @@ public class RenderEvents
}
if (player.isSneaking())
{
GlStateManager.translate(0, -0.3, 0);
}
IBakedModel model = ModelOverridesHandler.hasCustomOverrideModel(state, tag) ? ModelOverridesHandler.getCustomOverrideModel(state, tag, world, player) : Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(tileItem, world, player);
CarryOnOverride carryOverride = ScriptChecker.inspectBlock(state, world, player.getPosition(), tag);
if (carryOverride != null)
{
double[] translation = ScriptParseHelper.getXYZArray(carryOverride.getRenderTranslation());
double[] rot = ScriptParseHelper.getXYZArray(carryOverride.getRenderRotation());
double[] scale = ScriptParseHelper.getScale(carryOverride.getRenderScale());
Block b = StringParser.getBlock(carryOverride.getRenderNameBlock());
if (b != null)
{
ItemStack s = new ItemStack(b, 1, carryOverride.getRenderMeta());
s.setTagCompound(carryOverride.getRenderNBT());
model = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(s, world, player);
}
GlStateManager.translate(translation[0], translation[1], translation[2]);
GlStateManager.rotate((float) rot[0], 1, 0, 0);
GlStateManager.rotate((float) rot[1], 0, 1, 0);
GlStateManager.rotate((float) rot[2], 0, 0, 1);
GlStateManager.scale(scale[0], scale[1], scale[2]);
}
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);
Minecraft.getMinecraft().getRenderItem().renderItem(tileItem, model);
GlStateManager.scale(1, 1, 1);
{
Minecraft.getMinecraft().getRenderItem().renderItem(tileItem.isEmpty() ? stack : tileItem, model);
}
GlStateManager.scale(1, 1, 1);
GlStateManager.popMatrix();
}
}
/*
@ -313,111 +428,137 @@ public class RenderEvents
@SubscribeEvent
public void onPlayerRenderPre(RenderPlayerEvent.Pre event)
{
if (!Loader.isModLoaded("mobends") && CarryOnConfig.settings.renderArms)
{
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 (!initModels)
{
this.fakeLeftArm = new ModelRenderer(model, 32, 48);
this.fakeRightArm = new ModelRenderer(model, 40, 16);
this.fakeLeftArmwear = new ModelRenderer(model, 48, 48);
this.fakeRightArmwear = new ModelRenderer(model, 40, 32);
initModels = true;
}
player.setArrowCountInEntity(0); // TODO Temporary Fix
if (!stack.isEmpty() && (stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack)) || (stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack)))
if (!stack.isEmpty() && stack.getItem() == RegistrationHandler.itemTile && ItemTile.hasTileData(stack) || stack.getItem() == RegistrationHandler.itemEntity && ItemEntity.hasEntityData(stack))
{
if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty())
{
for (int k = 0; k < model.bipedBody.childModels.size(); k++)
{
float chkRot = model.bipedBody.childModels.get(k).rotateAngleX;
if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.6001F || chkRot == -1.7001F)
if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F)
{
model.bipedBody.childModels.remove(k);
k = k - 1;
}
}
}
Item item = stack.getItem();
model.bipedLeftArm.isHidden = true;
model.bipedRightArm.isHidden = true;
model.bipedLeftArmwear.isHidden = true;
model.bipedRightArmwear.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);
}
// left arm
this.fakeLeftArm.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 4, 12, 4, .08F);
this.fakeLeftArmwear.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 4, 12, 4, .08F + 0.25F);
if (aplayer.getSkinType().equals("default"))
{
fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.9F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 4, 12, 4, .08F);
// right arm
this.fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.9F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 4, 12, 4, .08F);
this.fakeRightArmwear.addBox(model.bipedRightArm.offsetX - 7.9F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 4, 12, 4, .08F + 0.25F);
}
else
{
fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.2F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 3, 12, 4, .08F);
// left arm
this.fakeLeftArm.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 3, 12, 4, .08F);
this.fakeLeftArmwear.addBox(model.bipedLeftArm.offsetX + 4.2F, model.bipedLeftArm.offsetY, model.bipedLeftArm.offsetZ, 3, 12, 4, .08F + 0.25F);
// right arm
this.fakeRightArm.addBox(model.bipedRightArm.offsetX - 7.2F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 3, 12, 4, .08F);
this.fakeRightArmwear.addBox(model.bipedRightArm.offsetX - 7.2F, model.bipedRightArm.offsetY, model.bipedRightArm.offsetZ, 3, 12, 4, .08F + 0.25F);
}
if (item == RegistrationHandler.itemTile)
{
if (!player.isSneaking())
{
fakeRightArm.rotateAngleX = -.9001F;
fakeLeftArm.rotateAngleX = -.9001F;
this.fakeRightArm.rotateAngleX = -.9001F;
this.fakeLeftArm.rotateAngleX = -.9001F;
this.fakeLeftArmwear.rotateAngleX = -.9001F;
this.fakeRightArmwear.rotateAngleX = -.9001F;
}
else
{
fakeRightArm.rotateAngleX = -1.6001F;
fakeLeftArm.rotateAngleX = -1.6001F;
this.fakeRightArm.rotateAngleX = -1.4001F;
this.fakeLeftArm.rotateAngleX = -1.4001F;
this.fakeLeftArmwear.rotateAngleX = -1.4001F;
this.fakeRightArmwear.rotateAngleX = -1.4001F;
}
}
else
{
if (!player.isSneaking())
{
fakeRightArm.rotateAngleX = -1.2001F;
fakeLeftArm.rotateAngleX = -1.2001F;
this.fakeRightArm.rotateAngleX = -1.2001F;
this.fakeLeftArm.rotateAngleX = -1.2001F;
this.fakeLeftArmwear.rotateAngleX = -1.2001F;
this.fakeRightArmwear.rotateAngleX = -1.2001F;
}
else
{
fakeRightArm.rotateAngleX = -1.7001F;
fakeLeftArm.rotateAngleX = -1.7001F;
this.fakeRightArm.rotateAngleX = -1.7001F;
this.fakeLeftArm.rotateAngleX = -1.7001F;
this.fakeLeftArmwear.rotateAngleX = -1.7001F;
this.fakeRightArmwear.rotateAngleX = -1.7001F;
}
fakeRightArm.rotateAngleY = -0.15f;
fakeLeftArm.rotateAngleY = 0.15f;
this.fakeRightArm.rotateAngleY = -0.15f;
this.fakeLeftArm.rotateAngleY = 0.15f;
this.fakeLeftArmwear.rotateAngleY = 0.15f;
this.fakeRightArmwear.rotateAngleY = -0.15f;
}
model.bipedBody.addChild(fakeLeftArm);
model.bipedBody.addChild(fakeRightArm);
model.bipedBody.addChild(this.fakeLeftArm);
model.bipedBody.addChild(this.fakeRightArm);
if (player.isWearing(EnumPlayerModelParts.LEFT_SLEEVE))
{
model.bipedBody.addChild(this.fakeLeftArmwear);
}
if (player.isWearing(EnumPlayerModelParts.RIGHT_SLEEVE))
{
model.bipedBody.addChild(this.fakeRightArmwear);
}
}
else
{
model.bipedLeftArm.isHidden = false;
model.bipedRightArm.isHidden = false;
model.bipedLeftArmwear.isHidden = false;
model.bipedRightArmwear.isHidden = false;
if (model.bipedBody.childModels != null && !model.bipedBody.childModels.isEmpty())
{
for (int k = 0; k < model.bipedBody.childModels.size(); k++)
{
float chkRot = model.bipedBody.childModels.get(k).rotateAngleX;
if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.6001F || chkRot == -1.7001F)
if (chkRot == -0.9001F || chkRot == -1.2001F || chkRot == -1.4001F || chkRot == -1.7001F)
{
model.bipedBody.childModels.remove(k);
k = k - 1;
@ -426,13 +567,14 @@ public class RenderEvents
}
}
if (stack.isEmpty() || (stack.getItem() != RegistrationHandler.itemTile && stack.getItem() != RegistrationHandler.itemEntity))
if (stack.isEmpty() || stack.getItem() != RegistrationHandler.itemTile && stack.getItem() != RegistrationHandler.itemEntity)
{
model.bipedLeftArm.isHidden = false;
model.bipedRightArm.isHidden = false;
model.bipedLeftArmwear.isHidden = false;
model.bipedRightArmwear.isHidden = false;
}
}
}
public static boolean isChest(Block block)
@ -466,5 +608,4 @@ public class RenderEvents
event.setRenderItem(false);
}
}
}

View File

@ -1,5 +1,11 @@
package tschipp.carryon.common;
import java.io.FileNotFoundException;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import net.minecraft.nbt.NBTException;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
@ -8,6 +14,7 @@ import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.relauncher.Side;
import tschipp.carryon.CarryOn;
import tschipp.carryon.common.handler.RegistrationHandler;
import tschipp.carryon.common.scripting.ScriptReader;
import tschipp.carryon.network.client.CarrySlotPacket;
import tschipp.carryon.network.client.CarrySlotPacketHandler;
import tschipp.carryon.network.server.SyncKeybindPacket;
@ -19,6 +26,8 @@ public class CommonProxy
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
ScriptReader.preInit(event);
CarryOn.network = NetworkRegistry.INSTANCE.newSimpleChannel("CarryOn");
CarryOn.network.registerMessage(SyncKeybindPacketHandler.class, SyncKeybindPacket.class, 0, Side.SERVER);
@ -31,6 +40,14 @@ public class CommonProxy
@EventHandler
public void init(FMLInitializationEvent event)
{
try
{
ScriptReader.parseScripts();
}
catch (JsonIOException | JsonSyntaxException | FileNotFoundException | NBTException e)
{
e.printStackTrace();
}
RegistrationHandler.regOverrideList();
}

View File

@ -21,6 +21,7 @@ import tschipp.carryon.common.handler.ModelOverridesHandler;
import tschipp.carryon.common.handler.RegistrationHandler;
import tschipp.carryon.common.item.ItemEntity;
import tschipp.carryon.common.item.ItemTile;
import tschipp.carryon.common.scripting.ScriptReader;
import tschipp.carryon.network.client.CarrySlotPacket;
public class CommandCarryOn extends CommandBase implements ICommand
@ -135,6 +136,11 @@ public class CommandCarryOn extends CommandBase implements ICommand
}
}
}
else if (args[0].toLowerCase().equals("reload"))
{
ScriptReader.reloadScripts();
sender.sendMessage(new TextComponentString("Successfully reloaded Scripts!"));
}
else
{
throw new WrongUsageException(this.getUsage(sender));

View File

@ -0,0 +1,78 @@
package tschipp.carryon.common.command;
import java.util.Collections;
import java.util.List;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.scripting.ScriptReader;
public class CommandCarryOnReload extends CommandBase
{
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (CarryOnConfig.settings.useScripts)
{
ScriptReader.reloadScripts();
sender.sendMessage(new TextComponentString("Successfully reloaded scripts!"));
}
else
sender.sendMessage(new TextComponentString("To use custom Carry On scripts, enable them in the config!"));
}
@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender)
{
return sender.canUseCommand(this.getRequiredPermissionLevel(), this.getName());
}
@Override
public int getRequiredPermissionLevel()
{
return 2;
}
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos)
{
if (args.length > 0)
{
if (args.length == 1)
{
return CommandBase.getListOfStringsMatchingLastWord(args, "reload");
}
else
{
return Collections.<String>emptyList();
}
}
return Collections.<String>emptyList();
}
@Override
public String getName()
{
return "reloadscripts";
}
@Override
public String getUsage(ICommandSender sender)
{
return "/reloadscripts";
}
}

View File

@ -54,6 +54,10 @@ public class Configs {
@Comment("Use Whitelist instead of Blacklist for Entities")
public boolean useWhitelistEntities=false;
@Config.RequiresMcRestart()
@Comment("Use custom Pickup Scripts. Having this set to false, will not allow you to run scripts, but will save you some performance")
public boolean useScripts=false;
}
public static class WhiteList

View File

@ -18,7 +18,23 @@ public class ListHandler
public static boolean isForbidden(Block block)
{
return FORBIDDEN_TILES.contains(block.getRegistryName().toString());
String name = block.getRegistryName().toString();
if (FORBIDDEN_TILES.contains(name))
return true;
else
{
boolean contains = false;
for (String s : FORBIDDEN_TILES)
{
if (s.contains("*"))
{
if(name.contains(s.replace("*", "")))
contains = true;
}
}
return contains;
}
}
public static boolean isForbidden(Entity entity)
@ -32,7 +48,8 @@ public class ListHandler
return true;
}
public static boolean isAllowed(Entity entity){
public static boolean isAllowed(Entity entity)
{
if (EntityList.getKey(entity) != null)
{
String name = EntityList.getKey(entity).toString();
@ -41,12 +58,28 @@ public class ListHandler
}
return true;
}
public static boolean isAllowed(Block block)
{
return ALLOWED_TILES.contains(block.getRegistryName().toString());
String name = block.getRegistryName().toString();
if (ALLOWED_TILES.contains(name))
return true;
else
{
boolean contains = false;
for (String s : ALLOWED_TILES)
{
if (s.contains("*"))
{
if(name.contains(s.replace("*", "")))
contains = true;
}
}
return contains;
}
}
public static void initForbiddenTiles()
{
String[] forbidden = CarryOnConfig.blacklist.forbiddenTiles;
@ -54,17 +87,6 @@ public class ListHandler
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++)
{
if (Block.REGISTRY.getKeys().toArray()[k].toString().contains(modid))
{
FORBIDDEN_TILES.add(Block.REGISTRY.getKeys().toArray()[k].toString());
}
}
}
FORBIDDEN_TILES.add(forbidden[i]);
}
@ -86,39 +108,29 @@ public class ListHandler
}
FORBIDDEN_ENTITIES.add(forbiddenEntity[i]);
}
String [] allowedEntities=CarryOnConfig.whitelist.allowedEntities;
ALLOWED_ENTITIES=new ArrayList<String>();
for(int i=0;i<allowedEntities.length;i++){
if(allowedEntities[i].contains("*"))
String[] allowedEntities = CarryOnConfig.whitelist.allowedEntities;
ALLOWED_ENTITIES = new ArrayList<String>();
for (int i = 0; i < allowedEntities.length; i++)
{
if (allowedEntities[i].contains("*"))
{
String modid=allowedEntities[i].replace("*", "");
for(int k=0;k<ForgeRegistries.ENTITIES.getKeys().size();k++)
String modid = allowedEntities[i].replace("*", "");
for (int k = 0; k < ForgeRegistries.ENTITIES.getKeys().size(); k++)
{
if(ForgeRegistries.ENTITIES.getKeys().toArray()[k].toString().contains(modid)){
if (ForgeRegistries.ENTITIES.getKeys().toArray()[k].toString().contains(modid))
{
ALLOWED_ENTITIES.add(ForgeRegistries.ENTITIES.getKeys().toArray()[k].toString());
}
}
}
ALLOWED_ENTITIES.add(allowedEntities[i]);
}
String[] allowedBlocks = CarryOnConfig.whitelist.allowedBlocks;
ALLOWED_TILES = new ArrayList<String>();
for (int i = 0; i < allowedBlocks.length; i++)
{
if (allowedBlocks[i].contains("*"))
{
String modid = allowedBlocks[i].replace("*", "");
for (int k = 0; k < Block.REGISTRY.getKeys().size(); k++)
{
if (Block.REGISTRY.getKeys().toArray()[k].toString().contains(modid))
{
ALLOWED_TILES.add(Block.REGISTRY.getKeys().toArray()[k].toString());
}
}
}
ALLOWED_TILES.add(allowedBlocks[i]);
}
}

View File

@ -16,6 +16,7 @@ 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.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
@ -23,6 +24,8 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.common.Loader;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.item.ItemTile;
import tschipp.carryon.common.scripting.CarryOnOverride;
import tschipp.carryon.common.scripting.ScriptChecker;
public class PickupHandler
{
@ -34,42 +37,54 @@ public class PickupHandler
player.closeScreen();
if (CarryOnConfig.settings.useWhitelistBlocks)
NBTTagCompound tag = new NBTTagCompound();
if (tile != null)
tile.writeToNBT(tag);
CarryOnOverride override = ScriptChecker.inspectBlock(world.getBlockState(pos), world, pos, tag);
if (override != null)
{
if (!ListHandler.isAllowed(world.getBlockState(pos).getBlock()))
{
return false;
}
return (ScriptChecker.fulfillsConditions(override, player)) && handleFTBUtils((EntityPlayerMP) player, world, pos, state);
}
else
{
if (ListHandler.isForbidden(world.getBlockState(pos).getBlock()))
if (CarryOnConfig.settings.useWhitelistBlocks)
{
return false;
}
}
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 (!ListHandler.isAllowed(world.getBlockState(pos).getBlock()))
{
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(state))
return false;
}
}
else
{
if (ListHandler.isForbidden(world.getBlockState(pos).getBlock()))
{
return false;
}
}
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))
{
IStageData stageData = PlayerDataHandler.getStageData(player);
String condition = CustomPickupOverrideHandler.getPickupCondition(state);
if (stageData.hasUnlockedStage(condition))
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);
}
}
else if (CarryOnConfig.settings.pickupAllBlocks ? true : tile != null)
{
return true && handleFTBUtils((EntityPlayerMP) player, world, pos, state);
}
}
}
}
@ -83,64 +98,31 @@ public class PickupHandler
if (toPickUp instanceof EntityPlayer)
return false;
// check for allow babies to be picked up
if (toPickUp instanceof EntityAgeable && CarryOnConfig.settings.allowBabies)
CarryOnOverride override = ScriptChecker.inspectEntity(toPickUp);
if (override != null)
{
EntityAgeable living = (EntityAgeable) toPickUp;
if (living.getGrowingAge() < 0 || living.isChild())
{
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;
}
}
}
if (CarryOnConfig.settings.useWhitelistEntities)
{
if (!ListHandler.isAllowed(toPickUp))
{
return false;
}
return (ScriptChecker.fulfillsConditions(override, player));
}
else
{
if (ListHandler.isForbidden(toPickUp))
// check for allow babies to be picked up
if (toPickUp instanceof EntityAgeable && CarryOnConfig.settings.allowBabies)
{
return false;
}
}
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))
EntityAgeable living = (EntityAgeable) toPickUp;
if (living.getGrowingAge() < 0 || living.isChild())
{
if (toPickUp instanceof EntityTameable)
double distance = pos.distanceSqToCenter(player.posX, player.posY + 0.5, player.posZ);
if (distance < Math.pow(CarryOnConfig.settings.maxDistance, 2))
{
EntityTameable tame = (EntityTameable) toPickUp;
if (tame.getOwnerId() != null && tame.getOwnerId() != player.getUUID(player.getGameProfile()))
return false;
if (toPickUp instanceof EntityTameable)
{
EntityTameable tame = (EntityTameable) toPickUp;
if (tame.getOwnerId() != null && tame.getOwnerId() != player.getUUID(player.getGameProfile()))
return false;
}
}
if (CustomPickupOverrideHandler.hasSpecialPickupConditions(toPickUp))
@ -154,6 +136,52 @@ public class PickupHandler
return true;
}
}
if (CarryOnConfig.settings.useWhitelistEntities)
{
if (!ListHandler.isAllowed(toPickUp))
{
return false;
}
}
else
{
if (ListHandler.isForbidden(toPickUp))
{
return false;
}
}
if ((CarryOnConfig.settings.pickupHostileMobs ? true : !toPickUp.isCreatureType(EnumCreatureType.MONSTER, false) || player.isCreative()))
{
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;

View File

@ -0,0 +1,296 @@
package tschipp.carryon.common.helper;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.scoreboard.Score;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.util.math.BlockPos;
public class ScriptParseHelper
{
public static boolean matches(double number, String cond)
{
if (cond == null)
return true;
try
{
if (cond.contains("<="))
{
return number >= Double.parseDouble(cond.replace("<=", ""));
}
if (cond.contains(">="))
{
return number <= Double.parseDouble(cond.replace(">=", ""));
}
if (cond.contains("<"))
{
return number > Double.parseDouble(cond.replace("<", ""));
}
if (cond.contains(">"))
{
return number < Double.parseDouble(cond.replace(">", ""));
}
if (cond.contains("="))
{
return number == Double.parseDouble(cond.replace("=", ""));
}
else
return number == Double.parseDouble(cond);
}
catch (Exception e)
{
new InvalidConfigException(e.getMessage()).printException();
}
return false;
}
public static boolean matches(Block block, String cond)
{
if (cond == null)
return true;
Block toCheck = StringParser.getBlock(cond);
if (toCheck != null)
return block == toCheck;
return false;
}
public static boolean matches(NBTTagCompound toCheck, NBTTagCompound toMatch)
{
if (toCheck == null || toMatch == null)
return true;
boolean matching = true;
for (String key : toMatch.getKeySet())
{
NBTBase tag = toMatch.getTag(key);
key = key.replace("\"", "");
NBTBase tagToCheck = toCheck.getTag(key);
if (!tag.equals(tagToCheck))
matching = false;
}
return matching;
}
public static double[] getXYZArray(String s)
{
double[] d = new double[3];
d[0] = getValueFromString(s, "x");
d[1] = getValueFromString(s, "y");
d[2] = getValueFromString(s, "z");
return d;
}
public static double[] getScale(String s)
{
double[] d = new double[3];
d[0] = getScaleValueFromString(s, "x");
d[1] = getScaleValueFromString(s, "y");
d[2] = getScaleValueFromString(s, "z");
return d;
}
public static double getScaleValueFromString(String toGetFrom, String key)
{
if(toGetFrom == null)
return 1;
String[] s = toGetFrom.split(",");
for (String string : s)
{
if (string.contains(key) && string.contains("="))
{
double numb = 1;
string = string.replace(key + "=", "");
try
{
numb = Double.parseDouble(string);
}
catch (Exception e)
{
}
return numb;
}
}
return 1;
}
public static boolean matchesScore(EntityPlayer player, String cond)
{
if (cond == null)
return true;
Scoreboard score = player.getWorldScoreboard();
String numb;
String scorename;
int iE = cond.indexOf("=");
int iG = cond.indexOf(">");
int iL = cond.indexOf("<");
if (iG == -1 ? true : iE < iG && iL == -1 ? true : iE < iL && iE != -1)
numb = cond.substring(iE);
else if (iE == -1 ? true : iG < iE && iL == -1 ? true : iG < iL && iG != -1)
numb = cond.substring(iG);
else
numb = cond.substring(iL);
scorename = cond.replace(numb, "");
Map<ScoreObjective, Score> o = score.getObjectivesForEntity(player.getGameProfile().getName());
if (o != null)
{
Score sc = o.get(score.getObjective(scorename));
if (sc != null)
{
int points = sc.getScorePoints();
return matches(points, numb);
}
}
return false;
}
public static boolean matches(BlockPos pos, String cond)
{
if (cond == null)
return true;
BlockPos blockpos = new BlockPos(getValueFromString(cond, "x"), getValueFromString(cond, "y"), getValueFromString(cond, "z"));
BlockPos expand = new BlockPos(getValueFromString(cond, "dx"), getValueFromString(cond, "dy"), getValueFromString(cond, "dz"));
BlockPos expanded = blockpos.add(expand);
boolean x = (pos.getX() >= blockpos.getX() && pos.getX() <= expanded.getX()) || blockpos.getX() == 0;
boolean y = (pos.getY() >= blockpos.getY() && pos.getY() <= expanded.getY()) || blockpos.getY() == 0;
boolean z = (pos.getZ() >= blockpos.getZ() && pos.getZ() <= expanded.getZ()) || blockpos.getZ() == 0;
return x && y && z;
}
public static double getValueFromString(String toGetFrom, String key)
{
if(toGetFrom == null)
return 0;
String[] s = toGetFrom.split(",");
for (String string : s)
{
if (string.contains(key) && string.contains("="))
{
double numb = 0;
string = string.replace(key + "=", "");
try
{
numb = Double.parseDouble(string);
}
catch (Exception e)
{
}
return numb;
}
}
return 0;
}
public static boolean matches(Material material, String cond)
{
if (cond == null)
return true;
switch (cond)
{
case "air":
return material == Material.AIR;
case "anvil":
return material == Material.ANVIL;
case "barrier":
return material == Material.BARRIER;
case "cactus":
return material == Material.CACTUS;
case "cake":
return material == Material.CAKE;
case "carpet":
return material == Material.CARPET;
case "circuits":
return material == Material.CIRCUITS;
case "clay":
return material == Material.CLAY;
case "cloth":
return material == Material.CLOTH;
case "coral":
return material == Material.CORAL;
case "dragon_egg":
return material == Material.DRAGON_EGG;
case "fire":
return material == Material.FIRE;
case "glass":
return material == Material.GLASS;
case "gourd":
return material == Material.GOURD;
case "grass":
return material == Material.GRASS;
case "ground":
return material == Material.GROUND;
case "ice":
return material == Material.ICE;
case "iron":
return material == Material.IRON;
case "lava":
return material == Material.LAVA;
case "leaves":
return material == Material.LEAVES;
case "packed_ice":
return material == Material.PACKED_ICE;
case "piston":
return material == Material.PISTON;
case "plants":
return material == Material.PLANTS;
case "portal":
return material == Material.PORTAL;
case "redstone_light":
return material == Material.REDSTONE_LIGHT;
case "rock":
return material == Material.ROCK;
case "sand":
return material == Material.SAND;
case "snow":
return material == Material.SNOW;
case "sponge":
return material == Material.SPONGE;
case "structure_void":
return material == Material.STRUCTURE_VOID;
case "tnt":
return material == Material.TNT;
case "vine":
return material == Material.VINE;
case "water":
return material == Material.WATER;
case "web":
return material == Material.WEB;
case "wood":
return material == Material.WOOD;
}
return false;
}
}

View File

@ -19,6 +19,9 @@ public class StringParser
@Nullable
public static Block getBlock(String string)
{
if(string == null)
return null;
NBTTagCompound tag = getTagCompound(string);
if (tag != null)
string = string.replace(tag.toString(), "");
@ -35,6 +38,9 @@ public class StringParser
public static int getMeta(String string)
{
if(string == null)
return 0;
NBTTagCompound tag = getTagCompound(string);
if (tag != null)
string = string.replace(tag.toString(), "");
@ -59,6 +65,9 @@ public class StringParser
@Nullable
public static IBlockState getBlockState(String string)
{
if(string == null)
return null;
NBTTagCompound tag = getTagCompound(string);
if (tag != null)
string = string.replace(tag.toString(), "");
@ -84,6 +93,9 @@ public class StringParser
@Nullable
public static Item getItem(String string)
{
if(string == null)
return null;
NBTTagCompound tag = getTagCompound(string);
if (tag != null)
string = string.replace(tag.toString(), "");
@ -96,6 +108,9 @@ public class StringParser
public static ItemStack getItemStack(String string)
{
if(string == null)
return null;
Item item = getItem(string);
if(item == null)
@ -113,6 +128,9 @@ public class StringParser
public static NBTTagCompound getTagCompound(String string)
{
NBTTagCompound tag = null;
if(string == null)
return null;
if (string.contains("{"))
{
if (!string.contains("}"))

View File

@ -0,0 +1,259 @@
package tschipp.carryon.common.scripting;
import net.minecraft.nbt.NBTTagCompound;
public class CarryOnOverride
{
//BLOCKS
private NBTTagCompound typeBlockTag;
private String typeMeta;
private String typeNameBlock;
private String typeMaterial;
private String typeHardness;
private String typeResistance;
//ENTITIES
private NBTTagCompound typeEntityTag;
private String typeNameEntity;
private String typeHeight;
private String typeWidth;
private String typeHealth;
//CONDITIONS
private String conditionGamestage;
private String conditionAchievement;
private String conditionXp;
private String conditionGamemode;
private String conditionScoreboard;
private String conditionPosition;
//RENDER
private String renderNameBlock;
private String renderNameEntity;
private int renderMeta;
private NBTTagCompound renderNBT;
private String renderTranslation;
private String renderRotation;
private String renderScale;
private boolean isBlock;
private boolean isEntity;
public boolean isBlock()
{
return isBlock;
}
public void setBlock(boolean isBlock)
{
this.isBlock = isBlock;
}
public boolean isEntity()
{
return isEntity;
}
public void setEntity(boolean isEntity)
{
this.isEntity = isEntity;
}
public NBTTagCompound getTypeBlockTag()
{
return typeBlockTag;
}
public String getTypeMeta()
{
return typeMeta;
}
public String getTypeNameBlock()
{
return typeNameBlock;
}
public String getTypeMaterial()
{
return typeMaterial;
}
public String getTypeHardness()
{
return typeHardness;
}
public String getTypeResistance()
{
return typeResistance;
}
public NBTTagCompound getTypeEntityTag()
{
return typeEntityTag;
}
public String getTypeNameEntity()
{
return typeNameEntity;
}
public String getTypeHeight()
{
return typeHeight;
}
public String getTypeWidth()
{
return typeWidth;
}
public String getTypeHealth()
{
return typeHealth;
}
public String getConditionGamestage()
{
return conditionGamestage;
}
public String getConditionAchievement()
{
return conditionAchievement;
}
public String getConditionXp()
{
return conditionXp;
}
public String getConditionGamemode()
{
return conditionGamemode;
}
public String getConditionScoreboard()
{
return conditionScoreboard;
}
public String getConditionPosition()
{
return conditionPosition;
}
public String getRenderNameBlock()
{
return renderNameBlock;
}
public String getRenderNameEntity()
{
return renderNameEntity;
}
public int getRenderMeta()
{
return renderMeta;
}
public NBTTagCompound getRenderNBT()
{
return renderNBT;
}
public String getRenderTranslation()
{
return renderTranslation;
}
public String getRenderRotation()
{
return renderRotation;
}
public String getRenderScale()
{
return renderScale;
}
public void setTypeBlockTag(NBTTagCompound typeBlockTag)
{
this.typeBlockTag = typeBlockTag;
}
public void setTypeMeta(String typeMeta)
{
this.typeMeta = typeMeta;
}
public void setTypeNameBlock(String typeNameBlock)
{
this.typeNameBlock = typeNameBlock;
}
public void setTypeMaterial(String typeMaterial)
{
this.typeMaterial = typeMaterial;
}
public void setTypeHardness(String typeHardness)
{
this.typeHardness = typeHardness;
}
public void setTypeResistance(String typeResistance)
{
this.typeResistance = typeResistance;
}
public void setTypeEntityTag(NBTTagCompound typeEntityTag)
{
this.typeEntityTag = typeEntityTag;
}
public void setTypeNameEntity(String typeNameEntity)
{
this.typeNameEntity = typeNameEntity;
}
public void setTypeHeight(String typeHeight)
{
this.typeHeight = typeHeight;
}
public void setTypeWidth(String typeWidth)
{
this.typeWidth = typeWidth;
}
public void setTypeHealth(String typeHealth)
{
this.typeHealth = typeHealth;
}
public void setConditionGamestage(String conditionGamestage)
{
this.conditionGamestage = conditionGamestage;
}
public void setConditionAchievement(String conditionAchievement)
{
this.conditionAchievement = conditionAchievement;
}
public void setConditionXp(String conditionXp)
{
this.conditionXp = conditionXp;
}
public void setConditionGamemode(String conditionGamemode)
{
this.conditionGamemode = conditionGamemode;
}
public void setConditionScoreboard(String conditionScoreboard)
{
this.conditionScoreboard = conditionScoreboard;
}
public void setConditionPosition(String conditionPosition)
{
this.conditionPosition = conditionPosition;
}
public void setRenderNameBlock(String renderNameBlock)
{
this.renderNameBlock = renderNameBlock;
}
public void setRenderNameEntity(String renderNameEntity)
{
this.renderNameEntity = renderNameEntity;
}
public void setRenderMeta(int renderMeta)
{
this.renderMeta = renderMeta;
}
public void setRenderNBT(NBTTagCompound renderNBT)
{
this.renderNBT = renderNBT;
}
public void setRenderTranslation(String renderTranslation)
{
this.renderTranslation = renderTranslation;
}
public void setRenderRotation(String renderRotation)
{
this.renderRotation = renderRotation;
}
public void setRenderScale(String renderScale)
{
this.renderScale = renderScale;
}
}

View File

@ -0,0 +1,114 @@
package tschipp.carryon.common.scripting;
import javax.annotation.Nullable;
import net.darkhax.gamestages.capabilities.PlayerDataHandler;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementManager;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.Loader;
import tschipp.carryon.common.config.CarryOnConfig;
import tschipp.carryon.common.helper.ScriptParseHelper;
public class ScriptChecker
{
@Nullable
public static CarryOnOverride inspectBlock(IBlockState state, World world, BlockPos pos, @Nullable NBTTagCompound tag)
{
if (!CarryOnConfig.settings.useScripts)
return null;
Block block = state.getBlock();
int meta = block.getMetaFromState(state);
Material material = state.getMaterial();
float hardness = state.getBlockHardness(world, pos);
float resistance = block.getExplosionResistance(null);
NBTTagCompound nbt = tag;
for (CarryOnOverride override : ScriptReader.OVERRIDES)
{
if (override.isBlock())
{
if (matchesAll(override, block, meta, material, hardness, resistance, nbt))
return override;
}
}
return null;
}
@Nullable
public static CarryOnOverride inspectEntity(Entity entity)
{
if (!CarryOnConfig.settings.useScripts)
return null;
String name = EntityList.getKey(entity).toString();
float height = entity.height;
float width = entity.width;
float health = entity instanceof EntityLivingBase ? ((EntityLivingBase) entity).getHealth() : 0.0f;
NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag);
for (CarryOnOverride override : ScriptReader.OVERRIDES)
{
if (override.isEntity())
{
if (matchesAll(override, name, height, width, health, tag))
return override;
}
}
return null;
}
public static boolean matchesAll(CarryOnOverride override, String name, float height, float width, float health, NBTTagCompound tag)
{
boolean matchname = name == null ? true : name.equals(override.getTypeNameEntity());
boolean matchheight = ScriptParseHelper.matches(height, override.getTypeHeight());
boolean matchwidth = ScriptParseHelper.matches(width, override.getTypeWidth());
boolean matchhealth = ScriptParseHelper.matches(health, override.getTypeHealth());
boolean matchnbt = ScriptParseHelper.matches(tag, override.getTypeEntityTag());
return (matchname && matchheight && matchwidth && matchhealth && matchnbt);
}
public static boolean matchesAll(CarryOnOverride override, Block block, int meta, Material material, float hardness, float resistance, NBTTagCompound nbt)
{
boolean matchnbt = ScriptParseHelper.matches(nbt, override.getTypeBlockTag());
boolean matchblock = ScriptParseHelper.matches(block, override.getTypeNameBlock());
boolean matchmeta = ScriptParseHelper.matches(meta, override.getTypeMeta());
boolean matchmaterial = ScriptParseHelper.matches(material, override.getTypeMaterial());
boolean matchhardness = ScriptParseHelper.matches(hardness, override.getTypeHardness());
boolean matchresistance = ScriptParseHelper.matches(resistance, override.getTypeResistance());
return (matchnbt && matchblock && matchmeta && matchmaterial && matchhardness && matchresistance);
}
public static boolean fulfillsConditions(CarryOnOverride override, EntityPlayer player)
{
AdvancementManager manager = ((WorldServer)((EntityPlayerMP)player).world).getAdvancementManager();
Advancement adv = manager.getAdvancement(new ResourceLocation((override.getConditionAchievement()) == null ? "" : override.getConditionAchievement()));
boolean achievement = adv == null ? true : ((EntityPlayerMP)player).getAdvancements().getProgress(adv).isDone();
boolean gamemode = ScriptParseHelper.matches(((EntityPlayerMP) player).interactionManager.getGameType().getID(), override.getConditionGamemode());
boolean gamestage = Loader.isModLoaded("gamestages") ? (override.getConditionGamestage() != null ? PlayerDataHandler.getStageData(player).hasUnlockedStage(override.getConditionGamestage()) : true) : true;
boolean position = ScriptParseHelper.matches(player.getPosition(), override.getConditionPosition());
boolean xp = ScriptParseHelper.matches(player.experienceLevel, override.getConditionXp());
boolean scoreboard = ScriptParseHelper.matchesScore(player, override.getConditionScoreboard());
return (achievement && gamemode && gamestage && position && xp && scoreboard);
}
}

View File

@ -0,0 +1,196 @@
package tschipp.carryon.common.scripting;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import tschipp.carryon.CarryOn;
import tschipp.carryon.common.config.CarryOnConfig;
public class ScriptReader
{
private static ArrayList<File> scripts = new ArrayList<File>();
public static HashSet<CarryOnOverride> OVERRIDES = new HashSet<CarryOnOverride>();
public static void preInit(FMLPreInitializationEvent event)
{
CarryOn.CONFIGURATION_FILE = new File(event.getModConfigurationDirectory(), "carryon-scripts/");
if (!CarryOn.CONFIGURATION_FILE.exists())
CarryOn.CONFIGURATION_FILE.mkdir();
for (File file : CarryOn.CONFIGURATION_FILE.listFiles())
{
if (file.getName().endsWith(".json"))
scripts.add(file);
}
}
public static void parseScripts() throws JsonIOException, JsonSyntaxException, FileNotFoundException, NBTException
{
if(!CarryOnConfig.settings.useScripts)
return;
for (File file : scripts)
{
boolean errored = false;
int hash = file.getAbsolutePath().hashCode();
JsonParser parser = new JsonParser();
JsonObject json = (JsonObject) parser.parse(new FileReader(file.getAbsolutePath()));
JsonObject object = (JsonObject) json.get("object");
JsonObject conditions = (JsonObject) json.get("conditions");
JsonObject render = (JsonObject) json.get("render");
if ((object != null && conditions != null) || (object != null && render != null))
{
JsonObject block = (JsonObject) object.get("block");
JsonObject entity = (JsonObject) object.get("entity");
if ((block == null && entity == null) || (block != null && entity != null))
errored = true;
if (!errored)
{
CarryOnOverride override = new CarryOnOverride();
if (block != null)
{
override.setBlock(true);
JsonElement name = block.get("name");
JsonElement meta = block.get("meta");
JsonElement material = block.get("material");
JsonElement hardness = block.get("hardness");
JsonElement resistance = block.get("resistance");
JsonObject nbt = (JsonObject) block.get("nbt");
if (name != null)
override.setTypeNameBlock(name.getAsString());
if (meta != null)
override.setTypeMeta(meta.getAsString());
if (material != null)
override.setTypeMaterial(material.getAsString());
if (hardness != null)
override.setTypeHardness(hardness.getAsString());
if (resistance != null)
override.setTypeResistance(resistance.getAsString());
if (nbt != null)
override.setTypeBlockTag(JsonToNBT.getTagFromJson(nbt.toString()));
}
else
{
override.setEntity(true);
JsonElement name = entity.get("name");
JsonElement health = entity.get("health");
JsonElement height = entity.get("height");
JsonElement width = entity.get("width");
JsonObject nbt = (JsonObject) entity.get("nbt");
if (name != null)
override.setTypeNameEntity(name.getAsString());
if (health != null)
override.setTypeHealth(health.getAsString());
if (height != null)
override.setTypeHeight(height.getAsString());
if (width != null)
override.setTypeWidth(width.getAsString());
if (nbt != null)
override.setTypeEntityTag(JsonToNBT.getTagFromJson(nbt.toString()));
}
if (conditions != null)
{
JsonElement gamestage = conditions.get("gamestage");
JsonElement achievement = conditions.get("advancement");
JsonElement xp = conditions.get("xp");
JsonElement gamemode = conditions.get("gamemode");
JsonElement scoreboard = conditions.get("scoreboard");
JsonElement position = conditions.get("position");
if(gamestage != null)
override.setConditionGamestage(gamestage.getAsString());
if(achievement != null)
override.setConditionAchievement(achievement.getAsString());
if(xp != null)
override.setConditionXp(xp.getAsString());
if(gamemode != null)
override.setConditionGamemode(gamemode.getAsString());
if(scoreboard != null)
override.setConditionScoreboard(scoreboard.getAsString());
if(position != null)
override.setConditionPosition(position.getAsString());
}
if (render != null)
{
JsonElement name_block = render.get("name_block");
JsonElement name_entity = render.get("name_entity");
JsonElement meta = render.get("meta");
JsonObject nbt = (JsonObject) render.get("nbt");
JsonElement translation = render.get("translation");
JsonElement rotation = render.get("rotation");
JsonElement scale = render.get("scale");
if(name_block != null)
override.setRenderNameBlock(name_block.getAsString());
if(name_entity != null)
override.setRenderNameEntity(name_entity.getAsString());
if(meta != null)
override.setRenderMeta(meta.getAsInt());
if(translation != null)
override.setRenderTranslation(translation.getAsString());
if(rotation != null)
override.setRenderRotation(rotation.getAsString());
if(scale != null)
override.setRenderScale(scale.getAsString());
if (nbt != null)
override.setRenderNBT(JsonToNBT.getTagFromJson(nbt.toString()));
}
OVERRIDES.add(override);
}
}
}
System.out.println("Successfully parsed scripts!");
}
public static void reloadScripts()
{
scripts.clear();
OVERRIDES.clear();
for (File file : CarryOn.CONFIGURATION_FILE.listFiles())
{
if (file.getName().endsWith(".json"))
scripts.add(file);
}
try
{
parseScripts();
}
catch (JsonIOException | JsonSyntaxException | FileNotFoundException | NBTException e)
{
e.printStackTrace();
}
}
}