Command rework (#1434)
* Network part finished. * Should be more reasonable now * This should be good enough. * Orb finished, needs strings * Bind finished. Needs strings. * Reformat & Help subcommand * Cleanup, strings, no negative amounts * Removed TODOs * Added missing MaxTier check for Blood Orbs. Added TODO: Test with custom Blood Orbs. * Ritual commands finished. Check for valid placement might be optimized. (TODO) * Access modifiers, moved TODO * Added TODOs for localized strings * DrainUtils postponed until the necessary functionality is available with SoulTickets (telling SoulTicket network from soul ticket, a list of all registered soul tickets per network) * Replaced all occurrences of TextHelper with TextComponentTranslation in the commands section * - Moved Teleports.java to teleport package - added teleposer command - added missing strings - cleanup * Fixed spelling of "Successful(ly)" * getUsage() now returns translation keys. getInfo() is now an explicit String ritual creation command now has proper tab completions help is an additional argument with "-h" or "?" cleanup * teleposerSet final cleanup. * Removed ritual removal command Signed-off-by: tobias <angryaeon@icloud.com> * Check if the tile has a ritual first Signed-off-by: tobias <angryaeon@icloud.com> * A bit more optimisation Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 1 Signed-off-by: tobias <angryaeon@icloud.com> * Cleanup part 2 Signed-off-by: tobias <angryaeon@icloud.com> * Part 3 Signed-off-by: tobias <angryaeon@icloud.com> * Part 4 Signed-off-by: tobias <angryaeon@icloud.com> * Updated language file to reflect cleanup & continuity changes. Signed-off-by: tobias <angryaeon@icloud.com> * Change to use an abstract class that gets called instead of calling super on overriden execute() for commands Signed-off-by: tobias <angryaeon@icloud.com> * Use player facing for ritual creation. Signed-off-by: tobias <angryaeon@icloud.com>
This commit is contained in:
parent
2a8e1f1271
commit
95d99c0a01
13 changed files with 990 additions and 323 deletions
|
@ -1,10 +1,12 @@
|
|||
package WayofTime.bloodmagic.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
|
||||
import WayofTime.bloodmagic.ritual.EnumRuneType;
|
||||
import WayofTime.bloodmagic.ritual.IRitualStone;
|
||||
import WayofTime.bloodmagic.ritual.Ritual;
|
||||
import WayofTime.bloodmagic.ritual.RitualComponent;
|
||||
import WayofTime.bloodmagic.tile.TileMasterRitualStone;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -14,6 +16,7 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -96,10 +99,8 @@ public class RitualHelper {
|
|||
return true;
|
||||
else if (tile instanceof IRitualStone.Tile)
|
||||
return true;
|
||||
else if (tile != null && tile.hasCapability(RUNE_CAPABILITY, null))
|
||||
return true;
|
||||
else return tile != null && tile.hasCapability(RUNE_CAPABILITY, null);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setRuneType(World world, BlockPos pos, EnumRuneType type) {
|
||||
|
@ -117,4 +118,94 @@ public class RitualHelper {
|
|||
world.notifyBlockUpdate(pos, state, state, 3);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean createRitual(World world, BlockPos pos, EnumFacing direction, Ritual ritual, boolean safe) {
|
||||
|
||||
List<RitualComponent> components = Lists.newArrayList();
|
||||
ritual.gatherComponents(components::add);
|
||||
|
||||
if (abortConstruction(world, pos, direction, safe, components)) return false;
|
||||
|
||||
IBlockState mrs = RegistrarBloodMagicBlocks.RITUAL_CONTROLLER.getDefaultState();
|
||||
world.setBlockState(pos, mrs);
|
||||
|
||||
setRitualStones(direction, world, pos, components);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean abortConstruction(World world, BlockPos pos, EnumFacing direction, boolean safe, List<RitualComponent> components) {
|
||||
//TODO: can be optimized to check only for the first and last component if every ritual has those at the highest and lowest y-level respectivly.
|
||||
for (RitualComponent component : components) {
|
||||
BlockPos offset = component.getOffset(direction);
|
||||
BlockPos newPos = pos.add(offset);
|
||||
if (world.isOutsideBuildHeight(newPos) || (safe && !world.isAirBlock(newPos)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean repairRitualFromRuins(TileMasterRitualStone tile, boolean safe) {
|
||||
Ritual ritual = tile.getCurrentRitual();
|
||||
EnumFacing direction;
|
||||
Pair<Ritual, EnumFacing> pair;
|
||||
if (ritual == null) {
|
||||
pair = getRitualFromRuins(tile);
|
||||
ritual = pair.getKey();
|
||||
direction = pair.getValue();
|
||||
} else
|
||||
direction = tile.getDirection();
|
||||
|
||||
World world = tile.getWorld();
|
||||
BlockPos pos = tile.getPos();
|
||||
|
||||
List<RitualComponent> components = Lists.newArrayList();
|
||||
ritual.gatherComponents(components::add);
|
||||
|
||||
if (abortConstruction(world, pos, direction, safe, components)) return false;
|
||||
|
||||
setRitualStones(direction, world, pos, components);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void setRitualStones(EnumFacing direction, World world, BlockPos pos, List<RitualComponent> gatheredComponents) {
|
||||
for (RitualComponent component : gatheredComponents) {
|
||||
BlockPos offset = component.getOffset(direction);
|
||||
BlockPos newPos = pos.add(offset);
|
||||
int meta = component.getRuneType().ordinal();
|
||||
IBlockState newState = RegistrarBloodMagicBlocks.RITUAL_STONE.getStateFromMeta(meta);
|
||||
world.setBlockState(newPos, newState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Pair<Ritual, EnumFacing> getRitualFromRuins(TileMasterRitualStone tile) {
|
||||
BlockPos pos = tile.getPos();
|
||||
World world = tile.getWorld();
|
||||
Ritual possibleRitual = tile.getCurrentRitual();
|
||||
EnumFacing possibleDirection = tile.getDirection();
|
||||
int highestCount = 0;
|
||||
|
||||
if (possibleRitual == null || possibleDirection == null)
|
||||
for (Ritual ritual : BloodMagic.RITUAL_MANAGER.getRituals()) {
|
||||
for (EnumFacing direction : EnumFacing.HORIZONTALS) {
|
||||
List<RitualComponent> components = Lists.newArrayList();
|
||||
ritual.gatherComponents(components::add);
|
||||
int currentCount = 0;
|
||||
|
||||
for (RitualComponent component : components) {
|
||||
BlockPos newPos = pos.add(component.getOffset(direction));
|
||||
if (isRuneType(world, newPos, component.getRuneType()))
|
||||
currentCount += 1;
|
||||
}
|
||||
if (currentCount > highestCount) {
|
||||
highestCount = currentCount;
|
||||
possibleRitual = ritual;
|
||||
possibleDirection = direction;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return Pair.of(possibleRitual, possibleDirection);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue