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 renderRotation;
private String renderScale; 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() public NBTTagCompound getTypeBlockTag()
{ {
return typeBlockTag; return typeBlockTag;

View File

@ -23,49 +23,53 @@ public class ScriptChecker
@Nullable @Nullable
public static CarryOnOverride inspectBlock(IBlockState state, World world, BlockPos pos, @Nullable NBTTagCompound tag) public static CarryOnOverride inspectBlock(IBlockState state, World world, BlockPos pos, @Nullable NBTTagCompound tag)
{ {
if(!CarryOnConfig.settings.useScripts) if (!CarryOnConfig.settings.useScripts)
return null; return null;
Block block = state.getBlock(); Block block = state.getBlock();
int meta = block.getMetaFromState(state); int meta = block.getMetaFromState(state);
Material material = state.getMaterial(); Material material = state.getMaterial();
float hardness = state.getBlockHardness(world, pos); float hardness = state.getBlockHardness(world, pos);
float resistance = block.getExplosionResistance(null); float resistance = block.getExplosionResistance(null);
NBTTagCompound nbt = tag; NBTTagCompound nbt = tag;
for(CarryOnOverride override : ScriptReader.OVERRIDES) for (CarryOnOverride override : ScriptReader.OVERRIDES)
{ {
if(matchesAll(override, block, meta, material, hardness, resistance, nbt)) if (override.isBlock())
return override; {
if (matchesAll(override, block, meta, material, hardness, resistance, nbt))
return override;
}
} }
return null; return null;
} }
@Nullable @Nullable
public static CarryOnOverride inspectEntity(Entity entity) public static CarryOnOverride inspectEntity(Entity entity)
{ {
if(!CarryOnConfig.settings.useScripts) if (!CarryOnConfig.settings.useScripts)
return null; return null;
String name = EntityList.getKey(entity).toString(); String name = EntityList.getKey(entity).toString();
float height = entity.height; float height = entity.height;
float width = entity.width; float width = entity.width;
float health = entity instanceof EntityLivingBase ? ((EntityLivingBase) entity).getHealth() : 0.0f; float health = entity instanceof EntityLivingBase ? ((EntityLivingBase) entity).getHealth() : 0.0f;
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag); entity.writeToNBT(tag);
for(CarryOnOverride override : ScriptReader.OVERRIDES) for (CarryOnOverride override : ScriptReader.OVERRIDES)
{ {
if(matchesAll(override, name, height, width, health, tag)) if (override.isEntity())
return override; {
if (matchesAll(override, name, height, width, health, tag))
return override;
}
} }
return null; return null;
} }
public static boolean matchesAll(CarryOnOverride override, String name, float height, float width, float health, NBTTagCompound tag) 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 matchname = name == null ? true : name.equals(override.getTypeNameEntity());
@ -73,10 +77,10 @@ public class ScriptChecker
boolean matchwidth = ScriptParseHelper.matches(width, override.getTypeWidth()); boolean matchwidth = ScriptParseHelper.matches(width, override.getTypeWidth());
boolean matchhealth = ScriptParseHelper.matches(health, override.getTypeHealth()); boolean matchhealth = ScriptParseHelper.matches(health, override.getTypeHealth());
boolean matchnbt = ScriptParseHelper.matches(tag, override.getTypeEntityTag()); boolean matchnbt = ScriptParseHelper.matches(tag, override.getTypeEntityTag());
return (matchname && matchheight && matchwidth && matchhealth && matchnbt); return (matchname && matchheight && matchwidth && matchhealth && matchnbt);
} }
public static boolean matchesAll(CarryOnOverride override, Block block, int meta, Material material, float hardness, float resistance, NBTTagCompound nbt) 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 matchnbt = ScriptParseHelper.matches(nbt, override.getTypeBlockTag());
@ -85,19 +89,19 @@ public class ScriptChecker
boolean matchmaterial = ScriptParseHelper.matches(material, override.getTypeMaterial()); boolean matchmaterial = ScriptParseHelper.matches(material, override.getTypeMaterial());
boolean matchhardness = ScriptParseHelper.matches(hardness, override.getTypeHardness()); boolean matchhardness = ScriptParseHelper.matches(hardness, override.getTypeHardness());
boolean matchresistance = ScriptParseHelper.matches(resistance, override.getTypeResistance()); boolean matchresistance = ScriptParseHelper.matches(resistance, override.getTypeResistance());
return (matchnbt && matchblock && matchmeta && matchmaterial && matchhardness && matchresistance); return (matchnbt && matchblock && matchmeta && matchmaterial && matchhardness && matchresistance);
} }
public static boolean fulfillsConditions(CarryOnOverride override, EntityPlayer player) public static boolean fulfillsConditions(CarryOnOverride override, EntityPlayer player)
{ {
boolean achievement = ScriptParseHelper.getAchievementFromString(override.getConditionAchievement()) == null ? true : player.hasAchievement(ScriptParseHelper.getAchievementFromString(override.getConditionAchievement())); 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 gamestage = Loader.isModLoaded("gamestages") ? (override.getConditionGamestage() != null ? PlayerDataHandler.getStageData(player).hasUnlockedStage(override.getConditionGamestage()) : true) : true;
boolean position = ScriptParseHelper.matches(player.getPosition(), override.getConditionPosition()); boolean position = ScriptParseHelper.matches(player.getPosition(), override.getConditionPosition());
boolean xp = ScriptParseHelper.matches(player.experienceLevel, override.getConditionXp()); boolean xp = ScriptParseHelper.matches(player.experienceLevel, override.getConditionXp());
boolean scoreboard = ScriptParseHelper.matchesScore(player, override.getConditionScoreboard()); boolean scoreboard = ScriptParseHelper.matchesScore(player, override.getConditionScoreboard());
return (achievement && gamemode && gamestage && position && xp && scoreboard); return (achievement && gamemode && gamestage && position && xp && scoreboard);
} }
} }

View File

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