Added Scripting
This commit is contained in:
parent
dde2408139
commit
57252bbae9
0
carryon-scripts
Normal file
0
carryon-scripts
Normal file
|
|
@ -1,9 +1,13 @@
|
|||
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;
|
||||
|
|
@ -16,6 +20,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)
|
||||
|
|
@ -33,17 +38,18 @@ public class CarryOn {
|
|||
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
|
||||
|
|
@ -55,6 +61,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.client.Minecraft;
|
||||
import net.minecraft.client.entity.AbstractClientPlayer;
|
||||
|
|
@ -15,9 +14,12 @@ 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.world.World;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
|
|
@ -29,8 +31,10 @@ 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
|
||||
{
|
||||
|
|
@ -159,6 +163,37 @@ public class RenderEntityEvents
|
|||
{
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
Minecraft.getMinecraft().getRenderManager().setRenderShadow(false);
|
||||
|
||||
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]);
|
||||
|
||||
}
|
||||
Minecraft.getMinecraft().getRenderManager().renderEntityStatic(entity, 0.0f, false);
|
||||
Minecraft.getMinecraft().getRenderManager().setRenderShadow(true);
|
||||
|
||||
|
|
@ -237,6 +272,38 @@ public class RenderEntityEvents
|
|||
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(c0, c1, c2);
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -19,8 +18,8 @@ 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.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;
|
||||
|
|
@ -44,8 +43,12 @@ 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
|
||||
|
|
@ -92,7 +95,6 @@ public class RenderEvents
|
|||
CarryOn.network.sendToServer(new SyncKeybindPacket(false));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,13 +152,11 @@ public class RenderEvents
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
int current = player.inventory.currentItem;
|
||||
|
||||
if(player.getEntityData().hasKey("carrySlot") ? player.getEntityData().getInteger("carrySlot") != current : false)
|
||||
player.inventory.currentItem = player.getEntityData().getInteger("carrySlot");
|
||||
|
||||
|
||||
int current = player.inventory.currentItem;
|
||||
|
||||
if (player.getEntityData().hasKey("carrySlot") ? player.getEntityData().getInteger("carrySlot") != current : false)
|
||||
player.inventory.currentItem = player.getEntityData().getInteger("carrySlot");
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -196,6 +196,29 @@ public class RenderEvents
|
|||
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, pos, 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]);
|
||||
|
||||
}
|
||||
|
||||
if (ModelOverridesHandler.hasCustomOverrideModel(state, tag))
|
||||
{
|
||||
Object override = ModelOverridesHandler.getOverrideObject(state, tag);
|
||||
|
|
@ -285,6 +308,30 @@ public class RenderEvents
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,58 +98,22 @@ 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 ((CarryOnConfig.settings.pickupHostileMobs ? true : !toPickUp.isCreatureType(EnumCreatureType.MONSTER, false) || player.isCreative()))
|
||||
{
|
||||
if ((toPickUp.height <= CarryOnConfig.settings.maxEntityHeight && toPickUp.width <= CarryOnConfig.settings.maxEntityWidth || player.isCreative()))
|
||||
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))
|
||||
{
|
||||
|
|
@ -158,6 +137,51 @@ public class PickupHandler
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,312 @@
|
|||
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.stats.Achievement;
|
||||
import net.minecraft.stats.AchievementList;
|
||||
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 Achievement getAchievementFromString(String s)
|
||||
{
|
||||
if (s == null)
|
||||
return null;
|
||||
|
||||
for (Achievement a : AchievementList.ACHIEVEMENTS)
|
||||
{
|
||||
if (a.statId.equals(s))
|
||||
return a;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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("}"))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,241 @@
|
|||
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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
package tschipp.carryon.common.scripting;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.darkhax.gamestages.capabilities.PlayerDataHandler;
|
||||
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.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
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(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(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)
|
||||
{
|
||||
boolean achievement = ScriptParseHelper.getAchievementFromString(override.getConditionAchievement()) == null ? true : player.hasAchievement(ScriptParseHelper.getAchievementFromString(override.getConditionAchievement()));
|
||||
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);
|
||||
}
|
||||
}
|
||||
194
src/main/java/tschipp/carryon/common/scripting/ScriptReader.java
Normal file
194
src/main/java/tschipp/carryon/common/scripting/ScriptReader.java
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
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("achievement");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user