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,6 +36,8 @@ public class CarryOnOverride
private String renderRotation; private String renderRotation;
private String renderScale; private String renderScale;
private boolean isBlock;
private boolean isEntity;
@ -43,6 +45,22 @@ public class CarryOnOverride
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,7 +23,7 @@ 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();
@ -33,20 +33,22 @@ public class ScriptChecker
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();
@ -56,16 +58,18 @@ public class ScriptChecker
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());
@ -92,7 +96,7 @@ public class ScriptChecker
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());

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");