Script Checker Entity/Block Conditional

This commit is contained in:
Tschipp 2017-09-28 16:51:55 +02:00
parent 82e43a37e5
commit ec04f72cc6
3 changed files with 49 additions and 25 deletions

View File

@ -36,13 +36,31 @@ public class CarryOnOverride
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;

View File

@ -23,49 +23,53 @@ public class ScriptChecker
@Nullable
public static CarryOnOverride inspectBlock(IBlockState state, World world, BlockPos pos, @Nullable NBTTagCompound tag)
{
if(!CarryOnConfig.settings.useScripts)
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)
for (CarryOnOverride override : ScriptReader.OVERRIDES)
{
if(matchesAll(override, block, meta, material, hardness, resistance, nbt))
return override;
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)
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)
for (CarryOnOverride override : ScriptReader.OVERRIDES)
{
if(matchesAll(override, name, height, width, health, tag))
return override;
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());
@ -73,10 +77,10 @@ public class ScriptChecker
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());
@ -85,19 +89,19 @@ public class ScriptChecker
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 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

@ -71,6 +71,7 @@ public class ScriptReader
if (block != null)
{
override.setBlock(true);
JsonElement name = block.get("name");
JsonElement meta = block.get("meta");
JsonElement material = block.get("material");
@ -93,6 +94,7 @@ public class ScriptReader
}
else
{
override.setEntity(true);
JsonElement name = entity.get("name");
JsonElement health = entity.get("health");
JsonElement height = entity.get("height");