Added getNewCopy() to Ritual to allow tiles to hold their own copy of a Ritual. Created caching in AreaDescriptor for faster BlockPos access.
This commit is contained in:
parent
69355f76fb
commit
d7a96c061d
|
@ -43,7 +43,8 @@ public class RitualRegistry
|
||||||
|
|
||||||
public static Ritual getRitualForId(String id)
|
public static Ritual getRitualForId(String id)
|
||||||
{
|
{
|
||||||
return registry.get(id);
|
Ritual ritual = registry.get(id);
|
||||||
|
return ritual != null ? ritual.getNewCopy() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getIdForRitual(Ritual ritual)
|
public static String getIdForRitual(Ritual ritual)
|
||||||
|
|
|
@ -23,6 +23,9 @@ public class AreaDescriptor
|
||||||
private BlockPos minimumOffset;
|
private BlockPos minimumOffset;
|
||||||
private BlockPos maximumOffset;
|
private BlockPos maximumOffset;
|
||||||
|
|
||||||
|
private ArrayList<BlockPos> blockPosCache = new ArrayList<BlockPos>();
|
||||||
|
private BlockPos cachedPosition = new BlockPos(0, 0, 0);
|
||||||
|
|
||||||
public Rectangle(BlockPos minimumOffset, BlockPos maximumOffset)
|
public Rectangle(BlockPos minimumOffset, BlockPos maximumOffset)
|
||||||
{
|
{
|
||||||
setOffsets(minimumOffset, maximumOffset);
|
setOffsets(minimumOffset, maximumOffset);
|
||||||
|
@ -31,22 +34,29 @@ public class AreaDescriptor
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPos> getContainedPositions(BlockPos pos)
|
public List<BlockPos> getContainedPositions(BlockPos pos)
|
||||||
{
|
{
|
||||||
ArrayList<BlockPos> posList = new ArrayList<BlockPos>();
|
if (!pos.equals(cachedPosition) || blockPosCache.isEmpty())
|
||||||
|
|
||||||
for (int i = minimumOffset.getX(); i <= maximumOffset.getX(); i++)
|
|
||||||
{
|
{
|
||||||
for (int j = minimumOffset.getY(); j <= maximumOffset.getY(); j++)
|
ArrayList<BlockPos> posList = new ArrayList<BlockPos>();
|
||||||
|
|
||||||
|
for (int i = minimumOffset.getX(); i <= maximumOffset.getX(); i++)
|
||||||
{
|
{
|
||||||
for (int k = minimumOffset.getZ(); k <= maximumOffset.getZ(); k++)
|
for (int j = minimumOffset.getY(); j <= maximumOffset.getY(); j++)
|
||||||
{
|
{
|
||||||
posList.add(pos.add(i, j, k));
|
for (int k = minimumOffset.getZ(); k <= maximumOffset.getZ(); k++)
|
||||||
|
{
|
||||||
|
posList.add(pos.add(i, j, k));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockPosCache = posList;
|
||||||
|
cachedPosition = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
return posList;
|
|
||||||
|
return blockPosCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AxisAlignedBB getAABB(BlockPos pos)
|
public AxisAlignedBB getAABB(BlockPos pos)
|
||||||
{
|
{
|
||||||
|
@ -65,6 +75,7 @@ public class AreaDescriptor
|
||||||
{
|
{
|
||||||
this.minimumOffset = new BlockPos(Math.min(offset1.getX(), offset2.getX()), Math.min(offset1.getY(), offset2.getY()), Math.min(offset1.getZ(), offset2.getZ()));
|
this.minimumOffset = new BlockPos(Math.min(offset1.getX(), offset2.getX()), Math.min(offset1.getY(), offset2.getY()), Math.min(offset1.getZ(), offset2.getZ()));
|
||||||
this.maximumOffset = new BlockPos(Math.max(offset1.getX(), offset2.getX()), Math.max(offset1.getY(), offset2.getY()), Math.max(offset1.getZ(), offset2.getZ()));
|
this.maximumOffset = new BlockPos(Math.max(offset1.getX(), offset2.getX()), Math.max(offset1.getY(), offset2.getY()), Math.max(offset1.getZ(), offset2.getZ()));
|
||||||
|
blockPosCache = new ArrayList<BlockPos>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public abstract class Ritual
|
||||||
private final RitualRenderer renderer;
|
private final RitualRenderer renderer;
|
||||||
private final String unlocalizedName;
|
private final String unlocalizedName;
|
||||||
|
|
||||||
private final Map<String, AreaDescriptor> modableRangeMap = new HashMap<String, AreaDescriptor>();
|
protected final Map<String, AreaDescriptor> modableRangeMap = new HashMap<String, AreaDescriptor>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name
|
* @param name
|
||||||
|
@ -165,4 +165,6 @@ public abstract class Ritual
|
||||||
{
|
{
|
||||||
REDSTONE, BREAK_MRS, BREAK_STONE, ACTIVATE, DEACTIVATE, EXPLOSION,
|
REDSTONE, BREAK_MRS, BREAK_STONE, ACTIVATE, DEACTIVATE, EXPLOSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract Ritual getNewCopy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,4 +84,10 @@ public class RitualGreenGrove extends Ritual
|
||||||
|
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ritual getNewCopy()
|
||||||
|
{
|
||||||
|
return new RitualGreenGrove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ public class RitualLava extends Ritual
|
||||||
if (currentEssence < getRefreshCost())
|
if (currentEssence < getRefreshCost())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
int maxEffects = currentEssence / getRefreshCost();
|
||||||
|
int totalEffects = 0;
|
||||||
|
|
||||||
AreaDescriptor lavaRange = getBlockRange(LAVA_RANGE);
|
AreaDescriptor lavaRange = getBlockRange(LAVA_RANGE);
|
||||||
|
|
||||||
for (BlockPos newPos : lavaRange.getContainedPositions(masterRitualStone.getPos()))
|
for (BlockPos newPos : lavaRange.getContainedPositions(masterRitualStone.getPos()))
|
||||||
|
@ -37,9 +40,16 @@ public class RitualLava extends Ritual
|
||||||
if (world.isAirBlock(newPos))
|
if (world.isAirBlock(newPos))
|
||||||
{
|
{
|
||||||
world.setBlockState(newPos, Blocks.lava.getDefaultState());
|
world.setBlockState(newPos, Blocks.lava.getDefaultState());
|
||||||
network.syphon(getRefreshCost());
|
totalEffects++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalEffects >= maxEffects)
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network.syphon(getRefreshCost() * totalEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,4 +73,10 @@ public class RitualLava extends Ritual
|
||||||
|
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ritual getNewCopy()
|
||||||
|
{
|
||||||
|
return new RitualLava();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,4 +60,10 @@ public class RitualTest extends Ritual
|
||||||
|
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ritual getNewCopy()
|
||||||
|
{
|
||||||
|
return new RitualTest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,16 +30,26 @@ public class RitualWater extends Ritual
|
||||||
if (currentEssence < getRefreshCost())
|
if (currentEssence < getRefreshCost())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AreaDescriptor lavaRange = getBlockRange(WATER_RANGE);
|
int maxEffects = currentEssence / getRefreshCost();
|
||||||
|
int totalEffects = 0;
|
||||||
|
|
||||||
|
AreaDescriptor waterRange = getBlockRange(WATER_RANGE);
|
||||||
|
|
||||||
for (BlockPos newPos : lavaRange.getContainedPositions(masterRitualStone.getPos()))
|
for (BlockPos newPos : waterRange.getContainedPositions(masterRitualStone.getPos()))
|
||||||
{
|
{
|
||||||
if (world.isAirBlock(newPos))
|
if (world.isAirBlock(newPos))
|
||||||
{
|
{
|
||||||
world.setBlockState(newPos, Blocks.water.getDefaultState());
|
world.setBlockState(newPos, Blocks.water.getDefaultState());
|
||||||
network.syphon(getRefreshCost());
|
totalEffects++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalEffects >= maxEffects)
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network.syphon(getRefreshCost() * totalEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,4 +73,10 @@ public class RitualWater extends Ritual
|
||||||
|
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Ritual getNewCopy()
|
||||||
|
{
|
||||||
|
return new RitualWater();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue