Skip to content

Commit

Permalink
Merge pull request #34 from Snakefangox/master
Browse files Browse the repository at this point in the history
Switched machines over to new tier system and added JSON and textures
  • Loading branch information
falseresync authored Jun 16, 2019
2 parents a0f5c53 + 7416ef5 commit f43a15b
Show file tree
Hide file tree
Showing 142 changed files with 998 additions and 385 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ dependencies {
compileOnly "com.google.code.findbugs:jsr305:3.0.2" // javax.annotations.*

modCompile ("alexiil.mc.lib:libblockattributes:0.4.2")
modCompile ("io.github.cottonmc:cotton:0.7.5+1.14.2-SNAPSHOT")
modCompile ("io.github.cottonmc:cotton:0.7.3+1.14.2-SNAPSHOT")
modCompile ("io.github.cottonmc:cotton-energy:1.4.0+1.14.2-SNAPSHOT")
modCompile ("io.github.cottonmc:cotton-resources:1.2.0+1.14.2-SNAPSHOT")
modCompile "me.shedaniel:RoughlyEnoughItems:2.9.1+build.116"

include ("alexill.mc.lib:libblockattributes:0.4.2")
include ("io.github.cottonmc:cotton-energy:1.4.0+1.14.2")
include ("alexiil.mc.lib:libblockattributes:0.4.2") { transitive = false }
include ("io.github.cottonmc:cotton-energy:1.4.0+1.14.2-SNAPSHOT") { transitive = false }
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vivatech/Vivatech.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class Vivatech implements ModInitializer {
public static final String MODID = "vivatech";
public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build(new Identifier(MODID, "item_group"),
() -> new ItemStack(VivatechItems.MACHINE_CHASSIS));
() -> new ItemStack(VivatechItems.REGULAR_MACHINE_CHASSIS));
public static final Item.Settings ITEM_SETTINGS = new Item.Settings().itemGroup(ITEM_GROUP);
public static final Block.Settings METALLIC_BLOCK_SETTINGS = FabricBlockSettings.copy(Blocks.IRON_BLOCK).build();
public static final Block.Settings MACHINE_BLOCK_SETTINGS = FabricBlockSettings.copy(Blocks.IRON_BLOCK).build();
Expand Down
37 changes: 34 additions & 3 deletions src/main/java/vivatech/block/AbstractTieredMachineBlock.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
package vivatech.block;

import java.util.List;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.ChatFormat;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.ItemStack;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.util.Identifier;
import net.minecraft.world.BlockView;
import vivatech.util.MachineTier;

public abstract class AbstractTieredMachineBlock extends AbstractMachineBlock {

public final MachineTier TIER;
protected final MachineTier tier;
protected final String id;

public AbstractTieredMachineBlock(Settings settings, MachineTier tier) {
public AbstractTieredMachineBlock(Settings settings, String id, MachineTier tier) {
super(settings);
TIER = tier;
this.id = id;
this.tier = tier;
}

public abstract Identifier getTieredID();

@Override
public String getTranslationKey() {
return "block.vivatech."+id;
}

@Environment(EnvType.CLIENT)
@Override
public void buildTooltip(ItemStack itemStack_1, BlockView blockView_1, List<Component> list_1, TooltipContext tooltipContext_1) {

Component tierLine = new TranslatableComponent("info.vivatech.tier", new TranslatableComponent("info.vivatech.tier."+(tier.toString().toLowerCase())));
tierLine.applyFormat(ChatFormat.GRAY);
list_1.add(tierLine);

super.buildTooltip(itemStack_1, blockView_1, list_1, tooltipContext_1);
}

public MachineTier getMachineTier() {
return tier;
}
}
15 changes: 12 additions & 3 deletions src/main/java/vivatech/block/CrusherBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@
import net.minecraft.world.World;
import vivatech.Vivatech;
import vivatech.entity.CrusherEntity;
import vivatech.util.MachineTier;
import vivatech.util.TierHelper;

public class CrusherBlock extends AbstractMachineBlock {
public class CrusherBlock extends AbstractTieredMachineBlock {
public static final Identifier ID = new Identifier(Vivatech.MODID, "crusher");
final Identifier TIERED_ID;

public CrusherBlock() {
super(Vivatech.MACHINE_BLOCK_SETTINGS);
public CrusherBlock(MachineTier tier) {
super(Vivatech.MACHINE_BLOCK_SETTINGS, "crusher", tier);
TIERED_ID = TierHelper.getTieredID(ID, tier);
}

@Override
public Identifier getTieredID() {
return TIERED_ID;
}

// Block
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/vivatech/block/ElectricFurnaceBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ElectricFurnaceBlock extends AbstractTieredMachineBlock {
final Identifier TIERED_ID;

public ElectricFurnaceBlock(MachineTier tier) {
super(Vivatech.MACHINE_BLOCK_SETTINGS, tier);
super(Vivatech.MACHINE_BLOCK_SETTINGS, "electric_furnace", tier);
TIERED_ID = TierHelper.getTieredID(ID, tier);
}

Expand All @@ -37,7 +37,7 @@ public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntit
// BlockEntityProvider
@Override
public BlockEntity createBlockEntity(BlockView blockView) {
return new ElectricFurnaceEntity(TIER);
return new ElectricFurnaceEntity();
}

@Override
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/vivatech/block/PressBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
import net.minecraft.world.World;
import vivatech.Vivatech;
import vivatech.entity.PressEntity;
import vivatech.util.MachineTier;
import vivatech.util.TierHelper;

public class PressBlock extends AbstractMachineBlock {
public class PressBlock extends AbstractTieredMachineBlock {
public static final Identifier ID = new Identifier(Vivatech.MODID, "press");
final Identifier TIERED_ID;

public PressBlock() {
super(Vivatech.MACHINE_BLOCK_SETTINGS);
public PressBlock(MachineTier tier) {
super(Vivatech.MACHINE_BLOCK_SETTINGS, "press", tier);
TIERED_ID = TierHelper.getTieredID(ID, tier);
}

@Override
public Identifier getTieredID() {
return TIERED_ID;
}

// Block
@Override
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/vivatech/entity/AbstractTieredMachineEntity.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package vivatech.entity;

import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
import vivatech.block.AbstractTieredMachineBlock;
import vivatech.util.MachineTier;

public abstract class AbstractTieredMachineEntity extends AbstractMachineEntity {

public MachineTier TIER;

public AbstractTieredMachineEntity(BlockEntityType<?> type, MachineTier tier) {
super(type);
TIER = tier;
}

public AbstractTieredMachineEntity(BlockEntityType<?> type) {
super(type);
}

public MachineTier getMachineTier() {
Block block = world.getBlockState(pos).getBlock();
if (block instanceof AbstractTieredMachineBlock) {
return ((AbstractTieredMachineBlock)block).getMachineTier();
} else {
return MachineTier.MINIMAL;
}
}
}
21 changes: 12 additions & 9 deletions src/main/java/vivatech/entity/CrusherEntity.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package vivatech.entity;

import javax.annotation.Nullable;

import alexiil.mc.lib.attributes.Simulation;
import net.minecraft.container.PropertyDelegate;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.Recipe;
import net.minecraft.util.math.Direction;
import vivatech.Vivatech;
import vivatech.init.VivatechEntities;
import vivatech.init.VivatechRecipes;
import vivatech.recipe.CrushingRecipe;
import vivatech.util.MachineTier;

import javax.annotation.Nullable;
public class CrusherEntity extends AbstractTieredMachineEntity {

public class CrusherEntity extends AbstractMachineEntity {
private static final int CONSUME_PER_TICK = 1;
private static final int TICK_PER_CONSUME = 5;
public static final int CONSUME_PER_TICK = 1;
public static final int TICK_PER_CONSUME = 5;
private int crushTime = 0;
private int crushTimeTotal = 0;
private final PropertyDelegate propertyDelegate = new PropertyDelegate() {
Expand Down Expand Up @@ -78,12 +79,14 @@ protected boolean canExtractEnergy() {

@Override
protected void serverTick() {
MachineTier tier = getMachineTier();

if (canRun()) {
crushTime++;
if (crushTime % TICK_PER_CONSUME == 0) energy.extractEnergy(Vivatech.INFINITE_VOLTAGE, CONSUME_PER_TICK, Simulation.ACTION);
if (crushTime % TICK_PER_CONSUME == 0) energy.extractEnergy(Vivatech.INFINITE_VOLTAGE, CONSUME_PER_TICK * (int)tier.getSpeedMultiplier(), Simulation.ACTION);
if (crushTimeTotal == 0) {
crushTimeTotal = world.getRecipeManager().getFirstMatch(VivatechRecipes.CRUSHING, this, world)
.map(CrushingRecipe::getProcessTime).orElse(200);
crushTimeTotal = (int) (world.getRecipeManager().getFirstMatch(VivatechRecipes.CRUSHING, this, world)
.map(CrushingRecipe::getProcessTime).orElse(200) / tier.getSpeedMultiplier());
}
setBlockActive(true);
if (crushTime >= crushTimeTotal) {
Expand All @@ -103,7 +106,7 @@ protected void serverTick() {

public ItemStack getOutputStack() {
if (!inventory.get(0).isEmpty()) {
Recipe recipe = world.getRecipeManager().getFirstMatch(VivatechRecipes.CRUSHING, this, world).orElse(null);
CrushingRecipe recipe = world.getRecipeManager().getFirstMatch(VivatechRecipes.CRUSHING, this, world).orElse(null);
return recipe != null ? recipe.getOutput().copy() : ItemStack.EMPTY;
}

Expand Down
18 changes: 7 additions & 11 deletions src/main/java/vivatech/entity/ElectricFurnaceEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.AbstractCookingRecipe;
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.SmeltingRecipe;
import net.minecraft.util.math.Direction;
import vivatech.Vivatech;
import vivatech.init.VivatechEntities;
Expand Down Expand Up @@ -62,10 +62,6 @@ public int size() {
}
};

public ElectricFurnaceEntity(MachineTier tier) {
super(VivatechEntities.ELECTRIC_FURNACE, tier);
}

public ElectricFurnaceEntity() {
super(VivatechEntities.ELECTRIC_FURNACE);
}
Expand All @@ -83,12 +79,14 @@ protected boolean canExtractEnergy() {

@Override
protected void serverTick() {
MachineTier tier = getMachineTier();

if (canRun()) {
cookTime++;
if (cookTime % TICK_PER_CONSUME == 0) energy.extractEnergy(Vivatech.INFINITE_VOLTAGE, CONSUME_PER_TICK * (int)TIER.getSpeedMultiplier(), Simulation.ACTION);
if (cookTime % TICK_PER_CONSUME == 0) energy.extractEnergy(Vivatech.INFINITE_VOLTAGE, CONSUME_PER_TICK * (int)tier.getSpeedMultiplier(), Simulation.ACTION);
if (cookTimeTotal == 0) {
cookTimeTotal = (int) (world.getRecipeManager().getFirstMatch(RecipeType.SMELTING, this, world)
.map(AbstractCookingRecipe::getCookTime).orElse(200) / (2 * TIER.getSpeedMultiplier()));
.map(AbstractCookingRecipe::getCookTime).orElse(200) / (2 * (tier.getSpeedMultiplier() + 0.5F)));
}
setBlockActive(true);
if (cookTime >= cookTimeTotal) {
Expand All @@ -108,7 +106,7 @@ protected void serverTick() {

public ItemStack getOutputStack() {
if (!inventory.get(0).isEmpty()) {
Recipe recipe = world.getRecipeManager().getFirstMatch(RecipeType.SMELTING, this, world).orElse(null);
SmeltingRecipe recipe = world.getRecipeManager().getFirstMatch(RecipeType.SMELTING, this, world).orElse(null);
return recipe != null ? recipe.getOutput().copy() : ItemStack.EMPTY;
}

Expand All @@ -120,7 +118,7 @@ public boolean canRun() {
if (inventory.get(0).isEmpty()
|| output.isEmpty()
|| inventory.get(1).getAmount() > 64
|| energy.getCurrentEnergy() < CONSUME_PER_TICK * TIER.getSpeedMultiplier()) {
|| energy.getCurrentEnergy() < CONSUME_PER_TICK * getMachineTier().getSpeedMultiplier()) {
return false;
} else if (!inventory.get(1).isEmpty()) {
return output.getItem() == inventory.get(1).getItem();
Expand Down Expand Up @@ -148,15 +146,13 @@ public void fromTag(CompoundTag tag) {
super.fromTag(tag);
cookTime = tag.getInt("CookTime");
cookTimeTotal = tag.getInt("CookTimeTotal");
TIER = MachineTier.values()[tag.getInt("Tier")];
}

@Override
public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag);
tag.putInt("CookTime", cookTime);
tag.putInt("CookTimeTotal", cookTimeTotal);
tag.putInt("Tier", TIER.ordinal());
return tag;
}

Expand Down
23 changes: 13 additions & 10 deletions src/main/java/vivatech/entity/PressEntity.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package vivatech.entity;

import javax.annotation.Nullable;

import alexiil.mc.lib.attributes.Simulation;
import net.minecraft.container.PropertyDelegate;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.Recipe;
import net.minecraft.util.math.Direction;
import vivatech.Vivatech;
import vivatech.init.VivatechEntities;
import vivatech.init.VivatechRecipes;
import vivatech.recipe.PressingRecipe;
import vivatech.util.MachineTier;

import javax.annotation.Nullable;
public class PressEntity extends AbstractTieredMachineEntity {

public class PressEntity extends AbstractMachineEntity {
private static final int TICK_PER_CONSUME = 5;
private static final int CONSUME_PER_TICK = 1;
public static final int TICK_PER_CONSUME = 5;
public static final int CONSUME_PER_TICK = 1;
private int pressTime = 0;
private int pressTimeTotal = 0;
private final PropertyDelegate propertyDelegate = new PropertyDelegate() {
Expand Down Expand Up @@ -60,7 +61,7 @@ public int size() {
return 4;
}
};

public PressEntity() {
super(VivatechEntities.PRESS);
}
Expand All @@ -78,12 +79,14 @@ protected boolean canExtractEnergy() {

@Override
protected void serverTick() {
MachineTier tier = getMachineTier();

if (canRun()) {
pressTime++;
if (pressTime % TICK_PER_CONSUME == 0) energy.extractEnergy(Vivatech.INFINITE_VOLTAGE, CONSUME_PER_TICK, Simulation.ACTION);
if (pressTime % TICK_PER_CONSUME == 0) energy.extractEnergy(Vivatech.INFINITE_VOLTAGE, CONSUME_PER_TICK * (int)tier.getSpeedMultiplier(), Simulation.ACTION);
if (pressTimeTotal == 0) {
pressTimeTotal = world.getRecipeManager().getFirstMatch(VivatechRecipes.PRESSING, this, world)
.map(PressingRecipe::getProcessTime).orElse(200);
pressTimeTotal = (int) (world.getRecipeManager().getFirstMatch(VivatechRecipes.PRESSING, this, world)
.map(PressingRecipe::getProcessTime).orElse(200) / tier.getSpeedMultiplier());
}
setBlockActive(true);
if (pressTime >= pressTimeTotal) {
Expand All @@ -103,7 +106,7 @@ protected void serverTick() {

public ItemStack getOutputStack() {
if (!inventory.get(0).isEmpty()) {
Recipe recipe = world.getRecipeManager().getFirstMatch(VivatechRecipes.PRESSING, this, world).orElse(null);
PressingRecipe recipe = world.getRecipeManager().getFirstMatch(VivatechRecipes.PRESSING, this, world).orElse(null);
return recipe != null ? recipe.getOutput().copy() : ItemStack.EMPTY;
}

Expand Down
Loading

0 comments on commit f43a15b

Please sign in to comment.