Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a ShapeRegistry #1826

Open
wants to merge 2 commits into
base: 1.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/mcjty/rftools/RFTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import mcjty.rftools.items.ModItems;
import mcjty.rftools.items.manual.GuiRFToolsManual;
import mcjty.rftools.proxy.CommonProxy;
import mcjty.rftools.shapes.ShapeRegistry;
import mcjty.rftools.wheelsupport.WheelSupport;
import mcjty.rftools.xnet.XNetSupport;
import net.minecraft.creativetab.CreativeTabs;
Expand Down Expand Up @@ -145,6 +146,7 @@ public void preInit(FMLPreInitializationEvent e) {
MainCompatHandler.registerWaila();
MainCompatHandler.registerTOP();
WheelSupport.registerWheel();
ShapeRegistry.registerCommonShapes();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import mcjty.rftools.network.PacketGetHudLog;
import mcjty.rftools.network.RFToolsMessages;
import mcjty.rftools.proxy.CommonProxy;
import mcjty.rftools.shapes.Shape;
import mcjty.rftools.shapes.IFormula;
import mcjty.theoneprobe.api.IProbeHitData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.ProbeMode;
Expand Down Expand Up @@ -323,9 +323,9 @@ private void makeSupportBlocksShaped() {
ItemStack shapeCard = inventoryHelper.getStackInSlot(SLOT_TAB);
BlockPos dimension = ShapeCardItem.getClampedDimension(shapeCard, BuilderConfiguration.maxBuilderDimension);
BlockPos offset = ShapeCardItem.getClampedOffset(shapeCard, BuilderConfiguration.maxBuilderOffset);
Shape shape = ShapeCardItem.getShape(shapeCard);
IFormula shape = ShapeCardItem.getShape(shapeCard);
Map<BlockPos, IBlockState> blocks = new HashMap<>();
ShapeCardItem.composeFormula(shapeCard, shape.getFormulaFactory().get(), getWorld(), getPos(), dimension, offset, blocks, BuilderConfiguration.maxBuilderDimension * 256 * BuilderConfiguration.maxBuilderDimension, false, false, null);
ShapeCardItem.composeFormula(shapeCard, shape, getWorld(), getPos(), dimension, offset, blocks, BuilderConfiguration.maxBuilderDimension * 256 * BuilderConfiguration.maxBuilderDimension, false, false, null);
for (Map.Entry<BlockPos, IBlockState> entry : blocks.entrySet()) {
BlockPos p = entry.getKey();
if (getWorld().isAirBlock(p)) {
Expand Down Expand Up @@ -384,9 +384,9 @@ private void clearSupportBlocksShaped() {
ItemStack shapeCard = inventoryHelper.getStackInSlot(SLOT_TAB);
BlockPos dimension = ShapeCardItem.getClampedDimension(shapeCard, BuilderConfiguration.maxBuilderDimension);
BlockPos offset = ShapeCardItem.getClampedOffset(shapeCard, BuilderConfiguration.maxBuilderOffset);
Shape shape = ShapeCardItem.getShape(shapeCard);
IFormula shape = ShapeCardItem.getShape(shapeCard);
Map<BlockPos, IBlockState> blocks = new HashMap<>();
ShapeCardItem.composeFormula(shapeCard, shape.getFormulaFactory().get(), getWorld(), getPos(), dimension, offset, blocks, BuilderConfiguration.maxSpaceChamberDimension * BuilderConfiguration.maxSpaceChamberDimension * BuilderConfiguration.maxSpaceChamberDimension, false, false, null);
ShapeCardItem.composeFormula(shapeCard, shape, getWorld(), getPos(), dimension, offset, blocks, BuilderConfiguration.maxSpaceChamberDimension * BuilderConfiguration.maxSpaceChamberDimension * BuilderConfiguration.maxSpaceChamberDimension, false, false, null);
for (Map.Entry<BlockPos, IBlockState> entry : blocks.entrySet()) {
BlockPos block = entry.getKey();
if (getWorld().getBlockState(block).getBlock() == BuilderSetup.supportBlock) {
Expand Down Expand Up @@ -954,12 +954,12 @@ private Map<BlockPos, IBlockState> getCachedBlocks(ChunkPos chunk) {
if (cachedBlocks == null) {
cachedBlocks = new HashMap<>();
ItemStack shapeCard = inventoryHelper.getStackInSlot(SLOT_TAB);
Shape shape = ShapeCardItem.getShape(shapeCard);
IFormula shape = ShapeCardItem.getShape(shapeCard);
boolean solid = ShapeCardItem.isSolid(shapeCard);
BlockPos dimension = ShapeCardItem.getClampedDimension(shapeCard, BuilderConfiguration.maxBuilderDimension);
BlockPos offset = ShapeCardItem.getClampedOffset(shapeCard, BuilderConfiguration.maxBuilderOffset);
boolean forquarry = !ShapeCardItem.isNormalShapeCard(shapeCard);
ShapeCardItem.composeFormula(shapeCard, shape.getFormulaFactory().get(), getWorld(), getPos(), dimension, offset, cachedBlocks, BuilderConfiguration.maxSpaceChamberDimension * BuilderConfiguration.maxSpaceChamberDimension * BuilderConfiguration.maxSpaceChamberDimension, solid, forquarry, chunk);
ShapeCardItem.composeFormula(shapeCard, shape, getWorld(), getPos(), dimension, offset, cachedBlocks, BuilderConfiguration.maxSpaceChamberDimension * BuilderConfiguration.maxSpaceChamberDimension * BuilderConfiguration.maxSpaceChamberDimension, solid, forquarry, chunk);
cachedChunk = chunk;
}
return cachedBlocks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import mcjty.lib.tileentity.GenericTileEntity;
import mcjty.rftools.blocks.builder.BuilderSetup;
import mcjty.rftools.items.builder.ShapeCardItem;
import mcjty.rftools.shapes.Shape;
import mcjty.rftools.shapes.ShapeModifier;
import mcjty.rftools.shapes.ShapeOperation;
import mcjty.rftools.shapes.ShapeRegistry;
import mcjty.rftools.shapes.ShapeRotation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -63,8 +63,8 @@ public void update() {
}
}
ShapeCardItem.setChildren(output, list);
if (!ShapeCardItem.getShape(output).isComposition()) {
ShapeCardItem.setShape(output, Shape.SHAPE_COMPOSITION, true);
if (! ShapeRegistry.isComposition(ShapeCardItem.getShape(output))) {
ShapeCardItem.setShape(output, ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_COMPOSITION), true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import mcjty.rftools.items.storage.StorageFilterCache;
import mcjty.rftools.items.storage.StorageFilterItem;
import mcjty.rftools.shapes.ScanDataManager;
import mcjty.rftools.shapes.Shape;
import mcjty.rftools.shapes.ShapeRegistry;
import mcjty.rftools.shapes.StatePalette;
import mcjty.rftools.varia.RLE;
import mcjty.theoneprobe.api.IProbeHitData;
Expand Down Expand Up @@ -279,9 +279,9 @@ public void setDataOffset(BlockPos dataOffset) {

private void updateScanCard(ItemStack cardOut) {
if (!cardOut.isEmpty()) {
if (!ShapeCardItem.getShape(cardOut).isScan()) {
if (! ShapeRegistry.isScan(ShapeCardItem.getShape(cardOut))) {
boolean solid = ShapeCardItem.isSolid(cardOut);
ShapeCardItem.setShape(cardOut, Shape.SHAPE_SCAN, solid);
ShapeCardItem.setShape(cardOut, ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_SCAN), solid);
}
NBTTagCompound tagOut = cardOut.getTagCompound();
if (dataDim != null) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mcjty/rftools/blocks/shield/ShieldTEBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import mcjty.rftools.blocks.shield.filters.*;
import mcjty.rftools.items.ModItems;
import mcjty.rftools.items.builder.ShapeCardItem;
import mcjty.rftools.shapes.Shape;
import mcjty.rftools.shapes.IFormula;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -634,12 +634,12 @@ public void composeShield(boolean ctrl) {
templateState = Blocks.AIR.getDefaultState();

ItemStack shapeItem = inventoryHelper.getStackInSlot(ShieldContainer.SLOT_SHAPE);
Shape shape = ShapeCardItem.getShape(shapeItem);
IFormula shape = ShapeCardItem.getShape(shapeItem);
boolean solid = ShapeCardItem.isSolid(shapeItem);
BlockPos dimension = ShapeCardItem.getClampedDimension(shapeItem, ShieldConfiguration.maxShieldDimension);
BlockPos offset = ShapeCardItem.getClampedOffset(shapeItem, ShieldConfiguration.maxShieldOffset);
Map<BlockPos, IBlockState> col = new HashMap<>();
ShapeCardItem.composeFormula(shapeItem, shape.getFormulaFactory().get(), getWorld(), getPos(), dimension, offset, col, supportedBlocks, solid, false, null);
ShapeCardItem.composeFormula(shapeItem, shape, getWorld(), getPos(), dimension, offset, col, supportedBlocks, solid, false, null);
coordinates = col;
} else {
if(!findTemplateState()) return;
Expand Down
28 changes: 7 additions & 21 deletions src/main/java/mcjty/rftools/items/builder/GuiShapeCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import mcjty.rftools.blocks.builder.BuilderConfiguration;
import mcjty.rftools.blocks.shaper.ScannerConfiguration;
import mcjty.rftools.network.RFToolsMessages;
import mcjty.rftools.shapes.IShapeParentGui;
import mcjty.rftools.shapes.PacketUpdateNBTShapeCard;
import mcjty.rftools.shapes.ShapeID;
import mcjty.rftools.shapes.ShapeRenderer;
import mcjty.rftools.shapes.*;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
Expand Down Expand Up @@ -154,18 +151,7 @@ public void initGui() {
getShapeRenderer().initView(getPreviewLeft(), guiTop);

shapeLabel = new ChoiceLabel(mc, this).setDesiredWidth(100).setDesiredHeight(16).addChoices(
mcjty.rftools.shapes.Shape.SHAPE_BOX.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_TOPDOME.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_BOTTOMDOME.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_SPHERE.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_CYLINDER.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_CAPPEDCYLINDER.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_PRISM.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_TORUS.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_CONE.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_HEART.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_COMPOSITION.getDescription(),
mcjty.rftools.shapes.Shape.SHAPE_SCAN.getDescription()
ShapeRegistry.getAllDescriptions()
).addChoiceEvent((parent, newChoice) -> updateSettings());

solidLabel = new ChoiceLabel(mc, this).setDesiredWidth(50).setDesiredHeight(16).addChoices(
Expand All @@ -175,7 +161,7 @@ public void initGui() {

Panel shapePanel = new Panel(mc, this).setLayout(new HorizontalLayout()).addChild(shapeLabel).addChild(solidLabel);

mcjty.rftools.shapes.Shape shape = ShapeCardItem.getShape(heldItem);
mcjty.rftools.shapes.IFormula shape = ShapeCardItem.getShape(heldItem);
shapeLabel.setChoice(shape.getDescription());
boolean solid = ShapeCardItem.isSolid(heldItem);
solidLabel.setChoice(solid ? "Solid" : "Hollow");
Expand Down Expand Up @@ -256,12 +242,12 @@ private void setupVoidPanel(ItemStack heldItem) {
}

private boolean isTorus() {
mcjty.rftools.shapes.Shape shape = getCurrentShape();
return mcjty.rftools.shapes.Shape.SHAPE_TORUS.equals(shape);
mcjty.rftools.shapes.IFormula shape = getCurrentShape();
return ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_TORUS).equals(shape);
}

private mcjty.rftools.shapes.Shape getCurrentShape() {
return mcjty.rftools.shapes.Shape.getShape(shapeLabel.getCurrentChoice());
private mcjty.rftools.shapes.IFormula getCurrentShape() {
return ShapeRegistry.getShapebyDescription(shapeLabel.getCurrentChoice());
}

private boolean isSolid() {
Expand Down
56 changes: 28 additions & 28 deletions src/main/java/mcjty/rftools/items/builder/ShapeCardItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos

setMode(stack, MODE_NONE);
setCorner1(stack, null);
setShape(stack, Shape.SHAPE_BOX, true);
setShape(stack, ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_BOX), true);
}
}
}
Expand Down Expand Up @@ -276,19 +276,19 @@ public void addInformation(ItemStack itemStack, World player, List<String> list,
}
}

Shape shape = getShape(itemStack);
IFormula shape = getShape(itemStack);
boolean issolid = isSolid(itemStack);
list.add(TextFormatting.GREEN + "Shape " + shape.getDescription() + " (" + (issolid ? "Solid" : "Hollow") + ")");
list.add(TextFormatting.GREEN + "Dimension " + BlockPosTools.toString(getDimension(itemStack)));
list.add(TextFormatting.GREEN + "Offset " + BlockPosTools.toString(getOffset(itemStack)));

if (shape.isComposition()) {
if (ShapeRegistry.isComposition(shape)) {
NBTTagCompound card = itemStack.getTagCompound();
NBTTagList children = card.getTagList("children", Constants.NBT.TAG_COMPOUND);
list.add(TextFormatting.DARK_GREEN + "Formulas: " + children.tagCount());
}

if (shape.isScan()) {
if (ShapeRegistry.isScan(shape)) {
NBTTagCompound card = itemStack.getTagCompound();
int scanid = card.getInteger("scanid");
list.add(TextFormatting.DARK_GREEN + "Scan id: " + scanid);
Expand Down Expand Up @@ -373,30 +373,30 @@ public static boolean isVoiding(ItemStack stack, String material) {
return tagCompound.getBoolean("void" + material);
}

public static Shape getShape(ItemStack stack) {
public static IFormula getShape(ItemStack stack) {
NBTTagCompound tagCompound = stack.getTagCompound();
return getShape(tagCompound);
}

public static Shape getShape(NBTTagCompound tagCompound) {
public static IFormula getShape(NBTTagCompound tagCompound) {
if (tagCompound == null) {
return Shape.SHAPE_BOX;
return ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_BOX);
}
if (!tagCompound.hasKey("shape") && !tagCompound.hasKey("shapenew")) {
return Shape.SHAPE_BOX;
return ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_BOX);
}
Shape shape;
IFormula shape;
if (tagCompound.hasKey("shapenew")) {
String sn = tagCompound.getString("shapenew");
shape = Shape.getShape(sn);
shape = ShapeRegistry.getShapebyDescription(sn);
} else {
int shapedeprecated = tagCompound.getInteger("shape");
ShapeDeprecated sd = ShapeDeprecated.getShape(shapedeprecated);
shape = sd.getNewshape();
}

if (shape == null) {
return Shape.SHAPE_BOX;
return ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_BOX);
}
return shape;
}
Expand Down Expand Up @@ -426,9 +426,9 @@ public static boolean isSolid(NBTTagCompound tagCompound) {
}

public static IFormula createCorrectFormula(NBTTagCompound tagCompound) {
Shape shape = getShape(tagCompound);
IFormula shape = getShape(tagCompound);
boolean solid = isSolid(tagCompound);
IFormula formula = shape.getFormulaFactory().get();
IFormula formula = shape;
return formula.correctFormula(solid);
}

Expand All @@ -437,8 +437,8 @@ public static int getScanId(ItemStack stack) {
return 0;
}
NBTTagCompound tagCompound = getCompound(stack);
Shape shape = getShape(tagCompound);
if (shape != Shape.SHAPE_SCAN) {
IFormula shape = getShape(tagCompound);
if (shape != ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_SCAN)) {
return 0;
}
return tagCompound.getInteger("scanid");
Expand All @@ -453,11 +453,11 @@ public static int getScanIdRecursive(ItemStack stack) {
}

private static int getScanIdRecursive(NBTTagCompound tagCompound) {
Shape shape = getShape(tagCompound);
if (tagCompound.hasKey("scanid") && shape == Shape.SHAPE_SCAN) {
IFormula shape = getShape(tagCompound);
if (tagCompound.hasKey("scanid") && shape == ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_SCAN)) {
return tagCompound.getInteger("scanid");
}
if (shape == Shape.SHAPE_COMPOSITION) {
if (shape == ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_COMPOSITION)) {
// See if there is a scan in the composition that has a scan id
NBTTagList children = tagCompound.getTagList("children", Constants.NBT.TAG_COMPOUND);
for (int i = 0 ; i < children.tagCount() ; i++) {
Expand All @@ -478,16 +478,16 @@ public static int getFormulaCheckClient(ItemStack stack) {
}

public static void getFormulaCheckClient(ItemStack stack, Check32 crc) {
Shape shape = getShape(stack);
IFormula formula = shape.getFormulaFactory().get();
IFormula shape = getShape(stack);
IFormula formula = shape;
formula.getCheckSumClient(stack.getTagCompound(), crc);
}

public static void getLocalChecksum(NBTTagCompound tagCompound, Check32 crc) {
if (tagCompound == null) {
return;
}
crc.add(getShape(tagCompound).ordinal());
crc.add(ShapeRegistry.ordinal(getShape(tagCompound)));
BlockPos dim = getDimension(tagCompound);
crc.add(dim.getX());
crc.add(dim.getY());
Expand All @@ -497,7 +497,7 @@ public static void getLocalChecksum(NBTTagCompound tagCompound, Check32 crc) {



public static void setShape(ItemStack stack, Shape shape, boolean solid) {
public static void setShape(ItemStack stack, IFormula shape, boolean solid) {
NBTTagCompound tagCompound = getCompound(stack);
if (isSolid(tagCompound) == solid && getShape(tagCompound).equals(shape)) {
// Nothing happens
Expand Down Expand Up @@ -682,11 +682,11 @@ public static int getRenderPositions(ItemStack stack, boolean solid, RLE positio


// Used for saving
public static int getDataPositions(ItemStack stack, Shape shape, boolean solid, RLE positions, StatePalette statePalette) {
public static int getDataPositions(ItemStack stack, IFormula shape, boolean solid, RLE positions, StatePalette statePalette) {
BlockPos dimension = ShapeCardItem.getDimension(stack);
BlockPos clamped = new BlockPos(Math.min(dimension.getX(), 512), Math.min(dimension.getY(), 256), Math.min(dimension.getZ(), 512));

IFormula formula = shape.getFormulaFactory().get();
IFormula formula = shape;
int dx = clamped.getX();
int dy = clamped.getY();
int dz = clamped.getZ();
Expand Down Expand Up @@ -787,7 +787,7 @@ public static void save(EntityPlayer player, ItemStack card, String filename) {
return;
}

Shape shape = ShapeCardItem.getShape(card);
IFormula shape = ShapeCardItem.getShape(card);
boolean solid = ShapeCardItem.isSolid(card);
BlockPos offset = ShapeCardItem.getOffset(card);
BlockPos dimension = ShapeCardItem.getDimension(card);
Expand Down Expand Up @@ -825,9 +825,9 @@ public static void load(EntityPlayer player, ItemStack card, String filename) {
return;
}

Shape shape = ShapeCardItem.getShape(card);
IFormula shape = ShapeCardItem.getShape(card);

if (shape != Shape.SHAPE_SCAN) {
if (shape != ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_SCAN)) {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "To load a file into this card you need a linked 'scan' type card!"), false);
return;
}
Expand Down Expand Up @@ -901,7 +901,7 @@ private static void setDataFromFile(int scanId, ItemStack card, BlockPos dimensi
scans.save(scanId);
ShapeCardItem.setDimension(card, dimension.getX(), dimension.getY(), dimension.getZ());
ShapeCardItem.setOffset(card, offset.getX(), offset.getY(), offset.getZ());
ShapeCardItem.setShape(card, Shape.SHAPE_SCAN, true);
ShapeCardItem.setShape(card, ShapeRegistry.getShapebyName(ShapeRegistry.CommonNames.SHAPE_SCAN), true);
}


Expand Down
Loading