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)
|
||||
{
|
||||
return registry.get(id);
|
||||
Ritual ritual = registry.get(id);
|
||||
return ritual != null ? ritual.getNewCopy() : null;
|
||||
}
|
||||
|
||||
public static String getIdForRitual(Ritual ritual)
|
||||
|
|
|
@ -23,6 +23,9 @@ public class AreaDescriptor
|
|||
private BlockPos minimumOffset;
|
||||
private BlockPos maximumOffset;
|
||||
|
||||
private ArrayList<BlockPos> blockPosCache = new ArrayList<BlockPos>();
|
||||
private BlockPos cachedPosition = new BlockPos(0, 0, 0);
|
||||
|
||||
public Rectangle(BlockPos minimumOffset, BlockPos maximumOffset)
|
||||
{
|
||||
setOffsets(minimumOffset, maximumOffset);
|
||||
|
@ -31,22 +34,29 @@ public class AreaDescriptor
|
|||
@Override
|
||||
public List<BlockPos> getContainedPositions(BlockPos pos)
|
||||
{
|
||||
ArrayList<BlockPos> posList = new ArrayList<BlockPos>();
|
||||
|
||||
for (int i = minimumOffset.getX(); i <= maximumOffset.getX(); i++)
|
||||
if (!pos.equals(cachedPosition) || blockPosCache.isEmpty())
|
||||
{
|
||||
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
|
||||
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.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 String unlocalizedName;
|
||||
|
||||
private final Map<String, AreaDescriptor> modableRangeMap = new HashMap<String, AreaDescriptor>();
|
||||
protected final Map<String, AreaDescriptor> modableRangeMap = new HashMap<String, AreaDescriptor>();
|
||||
|
||||
/**
|
||||
* @param name
|
||||
|
@ -165,4 +165,6 @@ public abstract class Ritual
|
|||
{
|
||||
REDSTONE, BREAK_MRS, BREAK_STONE, ACTIVATE, DEACTIVATE, EXPLOSION,
|
||||
}
|
||||
|
||||
public abstract Ritual getNewCopy();
|
||||
}
|
||||
|
|
|
@ -84,4 +84,10 @@ public class RitualGreenGrove extends Ritual
|
|||
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ritual getNewCopy()
|
||||
{
|
||||
return new RitualGreenGrove();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ public class RitualLava extends Ritual
|
|||
if (currentEssence < getRefreshCost())
|
||||
return;
|
||||
|
||||
int maxEffects = currentEssence / getRefreshCost();
|
||||
int totalEffects = 0;
|
||||
|
||||
AreaDescriptor lavaRange = getBlockRange(LAVA_RANGE);
|
||||
|
||||
for (BlockPos newPos : lavaRange.getContainedPositions(masterRitualStone.getPos()))
|
||||
|
@ -37,9 +40,16 @@ public class RitualLava extends Ritual
|
|||
if (world.isAirBlock(newPos))
|
||||
{
|
||||
world.setBlockState(newPos, Blocks.lava.getDefaultState());
|
||||
network.syphon(getRefreshCost());
|
||||
totalEffects++;
|
||||
}
|
||||
|
||||
if (totalEffects >= maxEffects)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
network.syphon(getRefreshCost() * totalEffects);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,4 +73,10 @@ public class RitualLava extends Ritual
|
|||
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ritual getNewCopy()
|
||||
{
|
||||
return new RitualLava();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,4 +60,10 @@ public class RitualTest extends Ritual
|
|||
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ritual getNewCopy()
|
||||
{
|
||||
return new RitualTest();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,16 +30,26 @@ public class RitualWater extends Ritual
|
|||
if (currentEssence < getRefreshCost())
|
||||
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))
|
||||
{
|
||||
world.setBlockState(newPos, Blocks.water.getDefaultState());
|
||||
network.syphon(getRefreshCost());
|
||||
totalEffects++;
|
||||
}
|
||||
|
||||
if (totalEffects >= maxEffects)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
network.syphon(getRefreshCost() * totalEffects);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,4 +73,10 @@ public class RitualWater extends Ritual
|
|||
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ritual getNewCopy()
|
||||
{
|
||||
return new RitualWater();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue