Skip to content

Commit

Permalink
2.7.0
Browse files Browse the repository at this point in the history
Layers can now be placed facing any direction.
Added new config options for debug output, *more* debug output, and dumping the artifice data.
Recipe stuff has been slighly redone yet again, PieceIngredients can now be tags.
Added more debug outputs.
  • Loading branch information
Shnupbups committed Aug 31, 2019
1 parent 4e04e49 commit 7a593cb
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 110 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.6.1+build.164

# Mod Properties
mod_version = 2.6.1
mod_version = 2.7.0
maven_group = com.shnupbups
archives_base_name = extrapieces

Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/shnupbups/extrapieces/ExtraPieces.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class ExtraPieces implements ModInitializer {

public static ArtificeResourcePack datapack;

public static boolean DUMP = false;

public static File configDir;
public static File ppDir;

Expand All @@ -39,6 +37,14 @@ public static Identifier getID(String path) {
public static void log(String out) {
logger.info("[" + mod_name + "] " + out);
}

public static void debugLog(String out) {
if(ModConfigs.debugOutput) log("[DEBUG] "+out);
}

public static void moreDebugLog(String out) {
if(ModConfigs.moreDebugOutput) debugLog(out);
}

public static Identifier prependToPath(Identifier id, String prep) {
return new Identifier(id.getNamespace(), prep + id.getPath());
Expand Down Expand Up @@ -69,11 +75,11 @@ public static boolean isWoodmillInstalled() {
}

public static void dump() {
if (DUMP) {
if (ModConfigs.dumpData) {
try {
datapack.dumpResources(FabricLoader.getInstance().getConfigDirectory().getParent() + "/dump");
} catch (Exception e) {
ExtraPieces.log("BIG OOF: " + e.getMessage());
ExtraPieces.debugLog("BIG OOF: " + e.getMessage());
}
}
}
Expand All @@ -82,13 +88,11 @@ public static void dump() {
public void onInitialize() {
ModConfigs.init();
FabricLoader.getInstance().getEntrypoints("extrapieces", EPInitializer.class).forEach(api -> {
log("EPInitializer " + api.toString());
debugLog("EPInitializer " + api.toString());
api.onInitialize();
});
ModConfigs.initPiecePacks();
datapack = Artifice.registerData(getID("ep_data"), data -> {
ModBlocks.init(data);
});
datapack = Artifice.registerData(getID("ep_data"), ModBlocks::init);
Registry.register(Registry.ITEM, getID("debug_item"), new DebugItem());

ServerStartCallback.EVENT.register(server -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateFactory;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
Expand All @@ -26,20 +27,20 @@
public class LayerPieceBlock extends Block implements Waterloggable, PieceBlock {
public static final IntProperty LAYERS;
public static final BooleanProperty WATERLOGGED;
protected static final VoxelShape[] LAYERS_TO_SHAPE;
public static final EnumProperty<Direction> FACING;

static {
LAYERS = Properties.LAYERS;
WATERLOGGED = Properties.WATERLOGGED;
LAYERS_TO_SHAPE = new VoxelShape[]{VoxelShapes.empty(), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 4.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 6.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 8.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 10.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 12.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 14.0D, 16.0D), Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D)};
FACING = Properties.FACING;
}

private final PieceSet set;

public LayerPieceBlock(PieceSet set) {
super(Settings.copy(set.getBase()));
this.set = set;
this.setDefaultState(this.stateFactory.getDefaultState().with(LAYERS, 1).with(WATERLOGGED, false));
this.setDefaultState(this.stateFactory.getDefaultState().with(LAYERS, 1).with(FACING, Direction.UP).with(WATERLOGGED, false));
}

public PieceSet getSet() {
Expand All @@ -54,19 +55,35 @@ public PieceType getType() {
return PieceTypes.LAYER;
}

public VoxelShape getOutlineShape(BlockState blockState_1, BlockView blockView_1, BlockPos blockPos_1, EntityContext entityContext_1) {
return LAYERS_TO_SHAPE[blockState_1.get(LAYERS)];
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext entityContext_1) {
Direction dir = state.get(FACING);
int layers = state.get(LAYERS);
if(layers == 8) return VoxelShapes.fullCube();
switch(dir) {
case UP:
return Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 2.0D*layers, 16.0D);
case DOWN:
return Block.createCuboidShape(0.0D, 16.0D-(layers*2.0D), 0.0D, 16.0D, 16.0D, 16.0D);
case EAST:
return Block.createCuboidShape(0.0D, 0.0D, 0.0D, 2.0D*layers, 16.0D, 16.0D);
case SOUTH:
return Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 2.0D*layers);
case WEST:
return Block.createCuboidShape(16.0D-(layers*2.0D), 0.0D, 0.0D, 16.0D, 16.0D, 16.0D);
case NORTH:
return Block.createCuboidShape(0.0D, 0.0D, 16.0D-(layers*2.0D), 16.0D, 16.0D, 16.0D);
} return VoxelShapes.empty();
}

public boolean hasSidedTransparency(BlockState blockState_1) {
return true;
}

public boolean canReplace(BlockState blockState_1, ItemPlacementContext itemPlacementContext_1) {
int int_1 = blockState_1.get(LAYERS);
public boolean canReplace(BlockState state, ItemPlacementContext itemPlacementContext_1) {
int int_1 = state.get(LAYERS);
if (itemPlacementContext_1.getStack().getItem() == this.asItem() && int_1 < 8) {
if (itemPlacementContext_1.canReplaceExisting()) {
return itemPlacementContext_1.getSide() == Direction.UP;
return itemPlacementContext_1.getSide() == state.get(FACING);
} else {
return true;
}
Expand All @@ -86,13 +103,14 @@ public BlockState getPlacementState(ItemPlacementContext itemPlacementContext_1)
return newState;
} else {
FluidState fluidState_1 = itemPlacementContext_1.getWorld().getFluidState(blockPos_1);
return this.getDefaultState().with(WATERLOGGED, fluidState_1.getFluid() == Fluids.WATER);
return this.getDefaultState().with(WATERLOGGED, fluidState_1.getFluid() == Fluids.WATER).with(FACING, itemPlacementContext_1.getSide());
}
}

protected void appendProperties(StateFactory.Builder<Block, BlockState> stateFactory$Builder_1) {
stateFactory$Builder_1.add(LAYERS);
stateFactory$Builder_1.add(WATERLOGGED);
stateFactory$Builder_1.add(FACING);
}

public FluidState getFluidState(BlockState blockState_1) {
Expand Down
32 changes: 19 additions & 13 deletions src/main/java/com/shnupbups/extrapieces/core/PieceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,29 +503,35 @@ public void addRecipes(ArtificeResourcePack.ServerResourcePackBuilder data) {
for (PieceRecipe pr : pb.getType().getCraftingRecipes()) {
if (pr.canAddForSet(this)) {
Identifier bid = Registry.BLOCK.getId(pb.getBlock());
Identifier id = ExtraPieces.getID(bid.getPath() + "_" + (i++));
pr.add(data, id, this);
ModRecipes.incrementRecipes();
if(!ModRecipes.checkIsAir(bid, this)) {
Identifier id = ExtraPieces.getID(bid.getPath() + "_" + (i++));
pr.add(data, id, this);
ModRecipes.incrementRecipes();
}
}
}

}
if (!isVanillaPiece(pb.getType()) && pb.getType() != PieceTypes.BASE && (isStonecuttable() || ModConfigs.everythingStonecuttable)) {
Identifier bid = Registry.BLOCK.getId(pb.getBlock());
Identifier id = ExtraPieces.getID(bid.getPath() + "_stonecutting");
StonecuttingPieceRecipe r = pb.getType().getStonecuttingRecipe();
if (r != null) {
r.add(data, id, this);
ModRecipes.incrementStonecuttingRecipes();
if(!ModRecipes.checkIsAir(bid, this)) {
Identifier id = ExtraPieces.getID(bid.getPath() + "_stonecutting");
StonecuttingPieceRecipe r = pb.getType().getStonecuttingRecipe();
if (r != null) {
r.add(data, id, this);
ModRecipes.incrementStonecuttingRecipes();
}
}
}
if (ExtraPieces.isWoodmillInstalled() && !isVanillaPiece(pb.getType()) && pb.getType() != PieceTypes.BASE && isWoodmillable()) {
Identifier bid = Registry.BLOCK.getId(pb.getBlock());
Identifier id = ExtraPieces.getID(bid.getPath() + "_woodmilling");
WoodmillingPieceRecipe r = pb.getType().getWoodmillingRecipe();
if (r != null) {
r.add(data, id, this);
ModRecipes.incrementWoodmillingRecipes();
if(!ModRecipes.checkIsAir(bid, this)) {
Identifier id = ExtraPieces.getID(bid.getPath() + "_woodmilling");
WoodmillingPieceRecipe r = pb.getType().getWoodmillingRecipe();
if (r != null) {
r.add(data, id, this);
ModRecipes.incrementWoodmillingRecipes();
}
}
}
}
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/com/shnupbups/extrapieces/pieces/LayerPiece.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.shnupbups.extrapieces.recipe.ShapedPieceRecipe;
import com.swordglowsblue.artifice.api.ArtificeResourcePack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;

import java.util.ArrayList;
Expand Down Expand Up @@ -47,11 +48,33 @@ public void addItemModel(ArtificeResourcePack.ClientResourcePackBuilder pack, Pi

public void addBlockstate(ArtificeResourcePack.ClientResourcePackBuilder pack, PieceBlock pb) {
pack.addBlockState(Registry.BLOCK.getId(pb.getBlock()), state -> {
for (int i = 1; i <= 8; i++) {
final int j = i * 2;
state.variant("layers=" + i, var -> {
var.model(ExtraPieces.prependToPath(ExtraPieces.appendToPath(Registry.BLOCK.getId(pb.getBlock()), "_height_" + j), "block/"));
});
for(Direction dir : Direction.values()) {
for (int i = 1; i <= 8; i++) {
final int j = i * 2;
state.variant("facing="+dir.asString()+",layers=" + i, var -> {
var.model(ExtraPieces.prependToPath(ExtraPieces.appendToPath(Registry.BLOCK.getId(pb.getBlock()), "_height_" + j), "block/"));
var.uvlock(true);
switch(dir) {
case DOWN:
var.rotationX(180);
return;
case NORTH:
var.rotationX(90);
return;
case SOUTH:
var.rotationX(90);
var.rotationY(180);
return;
case EAST:
var.rotationX(90);
var.rotationY(90);
return;
case WEST:
var.rotationX(90);
var.rotationY(270);
}
});
}
}
});
}
Expand Down
50 changes: 38 additions & 12 deletions src/main/java/com/shnupbups/extrapieces/recipe/PieceIngredient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,70 @@
import com.shnupbups.extrapieces.ExtraPieces;
import com.shnupbups.extrapieces.core.PieceSet;
import com.shnupbups.extrapieces.core.PieceType;
import com.shnupbups.extrapieces.core.PieceTypes;

import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.Items;
import net.minecraft.tag.Tag;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.Optional;

public class PieceIngredient {
public final PIType type;
private Item item;
private PieceType pt;
private Identifier id;

public PieceIngredient(PieceType type) {
this.type = PIType.PIECE;
this.pt = type;
this.id = type.getId();
}

public PieceIngredient(Item item) {
public PieceIngredient(ItemConvertible item) {
this.type = PIType.ITEM;
this.item = item;
this.id = Registry.ITEM.getId(item.asItem());
}

public PieceIngredient(Tag<Item> tag) {
this.type = PIType.TAG;
this.id = tag.getId();
}

public Item asItem(PieceSet set) {
if ((type == PIType.PIECE) && set.getPiece(pt).equals(Items.AIR)) {
ExtraPieces.log("Attempted to get type " + pt.toString() + " from set " + set.getName() + " for a recipe, but got air! This is not good!");
public Identifier getId(PieceSet set) {
if ((type == PIType.PIECE) && set.getPiece(getPieceType()).equals(Items.AIR)) {
ExtraPieces.log("Attempted to get type " + id.toString() + " from set " + set.getName() + " for a recipe, but got air! This is not good!");
}
switch (type) {
case ITEM:
return item;
case TAG:
return id;
case PIECE:
return set.getPiece(pt).asItem();
return Registry.ITEM.getId(set.getPiece(getPieceType()).asItem());
default:
return null;
}
}

public boolean isTag() {
return type == PIType.TAG;
}

public PieceType getPieceType() {
if(type == PIType.PIECE) {
Optional<PieceType> pt = PieceTypes.getTypeOrEmpty(id);
if(pt.isPresent()) return pt.get();
}
return null;
}

public boolean hasIngredientInSet(PieceSet set) {
return (type.equals(PIType.ITEM) || set.hasPiece(pt));
return (!type.equals(PIType.PIECE) || set.hasPiece(getPieceType()));
}

enum PIType {
ITEM,
PIECE
PIECE,
TAG
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public PieceRecipe(PieceType output, int count) {
this.output = output;
this.count = count;
}

public PieceRecipe(PieceType output) {
this(output, 1);
}

public PieceType getOutput() {
return output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import com.swordglowsblue.artifice.api.ArtificeResourcePack;
import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.tag.Tag;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class ShapedPieceRecipe extends PieceRecipe {
private HashMap<Character, PieceIngredient> key = new HashMap<>();
Expand All @@ -23,9 +26,13 @@ public ShapedPieceRecipe addToKey(char c, PieceType type) {
return addToKey(c, new PieceIngredient(type));
}

public ShapedPieceRecipe addToKey(char c, Item item) {
public ShapedPieceRecipe addToKey(char c, ItemConvertible item) {
return addToKey(c, new PieceIngredient(item));
}

public ShapedPieceRecipe addToKey(char c, Tag<Item> tag) {
return addToKey(c, new PieceIngredient(tag));
}

public ShapedPieceRecipe addToKey(char c, PieceIngredient ingredient) {
key.put(c, ingredient);
Expand All @@ -44,25 +51,14 @@ public PieceIngredient getFromKey(char c) {
return key.get(c);
}

public HashMap<Character, ItemConvertible> getKey(PieceSet set) {
HashMap<Character, ItemConvertible> setKey = new HashMap<>();
for (char c : getKey().keySet()) {
setKey.put(c, getFromKey(c).asItem(set));
}
return setKey;
}

public ItemConvertible getFromKey(PieceSet set, char c) {
return getFromKey(c).asItem(set);
}

public void add(ArtificeResourcePack.ServerResourcePackBuilder data, Identifier id, PieceSet set) {
data.addShapedRecipe(id, recipe -> {
recipe.result(Registry.BLOCK.getId(this.getOutput(set)), this.getCount());
recipe.group(Registry.BLOCK.getId(getOutput(set)));
recipe.pattern(this.getPattern());
for (char c : this.getKey(set).keySet()) {
recipe.ingredientItem(c, Registry.ITEM.getId(this.getFromKey(set, c).asItem()));
for (Map.Entry<Character, PieceIngredient> pi : this.getKey().entrySet()) {
if(pi.getValue().isTag()) recipe.ingredientTag(pi.getKey(), pi.getValue().getId(set));
else recipe.ingredientItem(pi.getKey(), pi.getValue().getId(set));
}
});
}
Expand Down
Loading

0 comments on commit 7a593cb

Please sign in to comment.