Added directionality to rituals.
This commit is contained in:
parent
971d4c4d1e
commit
0e1173ef5d
|
@ -21,6 +21,7 @@ public class Constants {
|
||||||
public static final String CURRENT_RITUAL = "currentRitual";
|
public static final String CURRENT_RITUAL = "currentRitual";
|
||||||
public static final String IS_RUNNING = "isRunning";
|
public static final String IS_RUNNING = "isRunning";
|
||||||
public static final String RUNTIME = "runtime";
|
public static final String RUNTIME = "runtime";
|
||||||
|
public static final String DIRECTION = "direction";
|
||||||
public static final String REAGENT_TANKS = "reagentTanks";
|
public static final String REAGENT_TANKS = "reagentTanks";
|
||||||
public static final String CURRENT_INCENSE = "BM:CurrentIncense";
|
public static final String CURRENT_INCENSE = "BM:CurrentIncense";
|
||||||
public static final String EMPTY = "Empty";
|
public static final String EMPTY = "Empty";
|
||||||
|
|
|
@ -37,4 +37,8 @@ public class RitualComponent {
|
||||||
return this.getOffset().getZ();
|
return this.getOffset().getZ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockPos getOffset(EnumFacing direction) {
|
||||||
|
return new BlockPos(getX(direction), offset.getY(), getZ(direction));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,17 +48,30 @@ public class RitualHelper {
|
||||||
* @param direction
|
* @param direction
|
||||||
* @return The ID of the valid ritual
|
* @return The ID of the valid ritual
|
||||||
*/
|
*/
|
||||||
public static String getValidRitual(World world, BlockPos pos, EnumFacing direction) {
|
public static String getValidRitual(World world, BlockPos pos) {
|
||||||
for(String key : RitualRegistry.getIds()) {
|
for(String key : RitualRegistry.getIds()) {
|
||||||
boolean test = checkValidRitual(world, pos, key, direction);
|
for(EnumFacing direction : EnumFacing.HORIZONTALS) {
|
||||||
if(test) {
|
boolean test = checkValidRitual(world, pos, key, direction);
|
||||||
return key;
|
if(test) {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static EnumFacing getDirectionOfRitual(World world, BlockPos pos, String key) {
|
||||||
|
for(EnumFacing direction : EnumFacing.HORIZONTALS) {
|
||||||
|
boolean test = checkValidRitual(world, pos, key, direction);
|
||||||
|
if(test) {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean checkValidRitual(World world, BlockPos pos, String ritualId, EnumFacing direction) {
|
public static boolean checkValidRitual(World world, BlockPos pos, String ritualId, EnumFacing direction) {
|
||||||
Ritual ritual = RitualRegistry.getRitualForId(ritualId);
|
Ritual ritual = RitualRegistry.getRitualForId(ritualId);
|
||||||
if(ritual == null) {
|
if(ritual == null) {
|
||||||
|
@ -71,7 +84,7 @@ public class RitualHelper {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (RitualComponent component : components) {
|
for (RitualComponent component : components) {
|
||||||
BlockPos newPos = pos.add(component.getOffset());
|
BlockPos newPos = pos.add(component.getOffset(direction));
|
||||||
IBlockState worldState = world.getBlockState(newPos);
|
IBlockState worldState = world.getBlockState(newPos);
|
||||||
Block block = worldState.getBlock();
|
Block block = worldState.getBlock();
|
||||||
if (block instanceof BlockRitualStone) {
|
if (block instanceof BlockRitualStone) {
|
||||||
|
|
|
@ -57,10 +57,13 @@ public class BlockRitualController extends BlockStringContainer {
|
||||||
|
|
||||||
if (getMetaFromState(state) == 0 && tile instanceof TileMasterRitualStone) {
|
if (getMetaFromState(state) == 0 && tile instanceof TileMasterRitualStone) {
|
||||||
if (player.getHeldItem() != null && player.getHeldItem().getItem() == ModItems.activationCrystal) {
|
if (player.getHeldItem() != null && player.getHeldItem().getItem() == ModItems.activationCrystal) {
|
||||||
String key = RitualHelper.getValidRitual(world, pos, null);
|
String key = RitualHelper.getValidRitual(world, pos);
|
||||||
|
EnumFacing direction = RitualHelper.getDirectionOfRitual(world, pos, key);
|
||||||
//TODO: Give a message stating that this ritual is not a valid ritual.
|
//TODO: Give a message stating that this ritual is not a valid ritual.
|
||||||
if (!key.isEmpty() && RitualHelper.checkValidRitual(world, pos, key, null)) {
|
if (!key.isEmpty() && direction != null && RitualHelper.checkValidRitual(world, pos, key, direction)) {
|
||||||
((TileMasterRitualStone) tile).activateRitual(player.getHeldItem(), player, RitualRegistry.getRitualForId(key));
|
if(((TileMasterRitualStone) tile).activateRitual(player.getHeldItem(), player, RitualRegistry.getRitualForId(key))) {
|
||||||
|
((TileMasterRitualStone) tile).setDirection(direction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (getMetaFromState(state) == 1 && tile instanceof TileImperfectRitualStone) {
|
} else if (getMetaFromState(state) == 1 && tile instanceof TileImperfectRitualStone) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
|
||||||
private int cooldown;
|
private int cooldown;
|
||||||
private Ritual currentRitual;
|
private Ritual currentRitual;
|
||||||
@Setter
|
@Setter
|
||||||
private EnumFacing direction;
|
private EnumFacing direction = EnumFacing.NORTH;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
|
@ -57,6 +57,7 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
|
||||||
currentRitual = RitualRegistry.getRitualForId(tag.getString(Constants.NBT.CURRENT_RITUAL));
|
currentRitual = RitualRegistry.getRitualForId(tag.getString(Constants.NBT.CURRENT_RITUAL));
|
||||||
active = tag.getBoolean(Constants.NBT.IS_RUNNING);
|
active = tag.getBoolean(Constants.NBT.IS_RUNNING);
|
||||||
activeTime = tag.getInteger(Constants.NBT.RUNTIME);
|
activeTime = tag.getInteger(Constants.NBT.RUNTIME);
|
||||||
|
direction = EnumFacing.VALUES[tag.getInteger(Constants.NBT.DIRECTION)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,6 +67,7 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
|
||||||
tag.setString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId);
|
tag.setString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId);
|
||||||
tag.setBoolean(Constants.NBT.IS_RUNNING, isActive());
|
tag.setBoolean(Constants.NBT.IS_RUNNING, isActive());
|
||||||
tag.setInteger(Constants.NBT.RUNTIME, getActiveTime());
|
tag.setInteger(Constants.NBT.RUNTIME, getActiveTime());
|
||||||
|
tag.setInteger(Constants.NBT.DIRECTION, direction.getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,7 +105,7 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
|
||||||
network.syphon(ritual.getActivationCost());
|
network.syphon(ritual.getActivationCost());
|
||||||
|
|
||||||
this.active = true;
|
this.active = true;
|
||||||
this.owner = PlayerHelper.getUUIDFromPlayer(activator).toString();
|
this.owner = crystalOwner; //Set the owner of the ritual to the crystal's owner
|
||||||
this.currentRitual = ritual;
|
this.currentRitual = ritual;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -117,7 +119,7 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performRitual(World world, BlockPos pos) {
|
public void performRitual(World world, BlockPos pos) {
|
||||||
if (getCurrentRitual() != null && RitualRegistry.ritualEnabled(getCurrentRitual()) && RitualHelper.checkValidRitual(getWorld(), getPos(), RitualRegistry.getIdForRitual(currentRitual), null)) {
|
if (getCurrentRitual() != null && RitualRegistry.ritualEnabled(getCurrentRitual()) && RitualHelper.checkValidRitual(getWorld(), getPos(), RitualRegistry.getIdForRitual(currentRitual), getDirection())) {
|
||||||
RitualEvent.RitualRunEvent event = new RitualEvent.RitualRunEvent(this, getOwner(), getCurrentRitual());
|
RitualEvent.RitualRunEvent event = new RitualEvent.RitualRunEvent(this, getOwner(), getCurrentRitual());
|
||||||
|
|
||||||
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||||
|
|
Loading…
Reference in a new issue