Skip to content

Commit

Permalink
Rename Coal Generator to Sterling Generator
Browse files Browse the repository at this point in the history
  • Loading branch information
falseresync committed Jul 28, 2019
1 parent 21a6877 commit bb39ff4
Show file tree
Hide file tree
Showing 25 changed files with 92 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
package vivatech.api.block.entity;

import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
import vivatech.api.block.ITieredBlock;
import vivatech.api.util.BlockTier;

public abstract class AbstractTieredMachineBlockEntity extends AbstractMachineBlockEntity implements ITieredBlockEntity {
public AbstractTieredMachineBlockEntity(BlockEntityType<?> type) {
super(type);
}

@Override
public BlockTier getTier() {
Block block = world.getBlockState(pos).getBlock();
if (block instanceof ITieredBlock) {
return ((ITieredBlock) block).getTier();
} else {
return BlockTier.MINIMAL;
}
}
}
16 changes: 15 additions & 1 deletion src/main/java/vivatech/api/block/entity/ITieredBlockEntity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
package vivatech.api.block.entity;

import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import vivatech.api.block.ITieredBlock;
import vivatech.api.util.BlockTier;

/**
* WARNING: Only apply on BlockEntity!
*/
public interface ITieredBlockEntity {
BlockTier getTier();
default BlockTier getTier() {
BlockEntity self = (BlockEntity) this;
Block block = self.getWorld().getBlockState(self.getPos()).getBlock();
if (block instanceof ITieredBlock) {
return ((ITieredBlock) block).getTier();
} else {
return BlockTier.MINIMAL;
}
};
}
2 changes: 1 addition & 1 deletion src/main/java/vivatech/client/VivatechClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class VivatechClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
ScreenProviderRegistry.INSTANCE.registerFactory(CoalGeneratorBlock.ID, (syncId, identifier, player, buf) ->
ScreenProviderRegistry.INSTANCE.registerFactory(SterlingGeneratorBlock.ID, (syncId, identifier, player, buf) ->
new CoalGeneratorScreen(new CoalGeneratorMenu(
syncId, player.inventory, BlockContext.create(player.world, buf.readBlockPos())), player));
ScreenProviderRegistry.INSTANCE.registerFactory(CrusherBlock.ID, (syncId, identifier, player, buf) ->
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/vivatech/client/screen/CoalGeneratorScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.github.cottonmc.cotton.gui.client.CottonScreen;
import io.github.cottonmc.cotton.gui.widget.WLabel;
import net.minecraft.entity.player.PlayerEntity;
import vivatech.common.block.CoalGeneratorBlock;
import vivatech.common.block.SterlingGeneratorBlock;
import vivatech.common.menu.CoalGeneratorMenu;
import vivatech.util.StringHelper;

Expand All @@ -17,7 +17,7 @@ protected void drawBackground(float partialTicks, int mouseX, int mouseY) {
super.drawBackground(partialTicks, mouseX, mouseY);

// Title
String title = StringHelper.getTranslatableComponent("block", CoalGeneratorBlock.ID).asString();
String title = StringHelper.getTranslatableComponent("block", SterlingGeneratorBlock.ID).asString();
font.draw(title, left + 81 - font.getStringWidth(title) / 2, top, WLabel.DEFAULT_TEXT_COLOR);
}
}
2 changes: 1 addition & 1 deletion src/main/java/vivatech/common/Vivatech.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onInitialize() {
VivatechEntities.initialize();
VivatechItems.initialize();

ContainerProviderRegistry.INSTANCE.registerFactory(CoalGeneratorBlock.ID, (syncId, id, player, buf) ->
ContainerProviderRegistry.INSTANCE.registerFactory(SterlingGeneratorBlock.ID, (syncId, id, player, buf) ->
new CoalGeneratorMenu(syncId, player.inventory, BlockContext.create(player.world, buf.readBlockPos())));
ContainerProviderRegistry.INSTANCE.registerFactory(CrusherBlock.ID, (syncId, id, player, buf) ->
new CrusherMenu(syncId, player.inventory, BlockContext.create(player.world, buf.readBlockPos())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import net.minecraft.world.World;
import vivatech.common.Vivatech;
import vivatech.api.block.AbstractMachineBlock;
import vivatech.common.block.entity.CoalGeneratorBlockEntity;
import vivatech.common.block.entity.SterlingGeneratorBlockEntity;

public class CoalGeneratorBlock extends AbstractMachineBlock {
public static final Identifier ID = new Identifier(Vivatech.MODID, "coal_generator");
public class SterlingGeneratorBlock extends AbstractMachineBlock {
public static final Identifier ID = new Identifier(Vivatech.MODID, "sterling_generator");

public CoalGeneratorBlock() {
public SterlingGeneratorBlock() {
super(Vivatech.MACHINE_BLOCK_SETTINGS);
}

Expand All @@ -34,6 +34,6 @@ public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntit
// BlockEntityProvider
@Override
public BlockEntity createBlockEntity(BlockView blockView) {
return new CoalGeneratorBlockEntity();
return new SterlingGeneratorBlockEntity();
}
}
16 changes: 13 additions & 3 deletions src/main/java/vivatech/common/block/entity/CrusherBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ protected void serverTick() {
}
}

public ItemStack getInputStack() {
if (!inventory.get(0).isEmpty()) {
CrushingRecipe recipe = world.getRecipeManager().getFirstMatch(VivatechRecipes.CRUSHING, this, world).orElse(null);
return recipe != null ? recipe.getInput().getStackArray()[0].copy() : ItemStack.EMPTY;
}

return ItemStack.EMPTY;
}

public ItemStack getOutputStack() {
if (!inventory.get(0).isEmpty()) {
CrushingRecipe recipe = world.getRecipeManager().getFirstMatch(VivatechRecipes.CRUSHING, this, world).orElse(null);
Expand All @@ -129,15 +138,16 @@ public boolean canRun() {
}

public void crushItem() {
ItemStack input = getInputStack();
ItemStack output = getOutputStack();
if (!output.isEmpty()) {
if (!output.isEmpty() && !input.isEmpty()) {
if (inventory.get(1).isEmpty()) {
inventory.set(1, output);
} else {
inventory.get(1).increment(1);
inventory.get(1).increment(output.getCount());
}

inventory.get(0).decrement(1);
inventory.get(0).decrement(input.getCount());
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/vivatech/common/block/entity/PressBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ protected void serverTick() {
}
}

public ItemStack getInputStack() {
if (!inventory.get(0).isEmpty()) {
PressingRecipe recipe = world.getRecipeManager().getFirstMatch(VivatechRecipes.PRESSING, this, world).orElse(null);
return recipe != null ? recipe.getInput().getStackArray()[0].copy() : ItemStack.EMPTY;
}

return ItemStack.EMPTY;
}


public ItemStack getOutputStack() {
if (!inventory.get(0).isEmpty()) {
PressingRecipe recipe = world.getRecipeManager().getFirstMatch(VivatechRecipes.PRESSING, this, world).orElse(null);
Expand All @@ -129,15 +139,16 @@ public boolean canRun() {
}

public void pressItem() {
ItemStack input = getInputStack();
ItemStack output = getOutputStack();
if (!output.isEmpty()) {
if (!output.isEmpty() && !input.isEmpty()) {
if (inventory.get(1).isEmpty()) {
inventory.set(1, output);
} else {
inventory.get(1).increment(1);
inventory.get(1).increment(output.getCount());
}

inventory.get(0).decrement(1);
inventory.get(0).decrement(input.getCount());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import javax.annotation.Nullable;

public class CoalGeneratorBlockEntity extends AbstractMachineBlockEntity {
public class SterlingGeneratorBlockEntity extends AbstractMachineBlockEntity {
private static final int GENERATE_PER_TICK = 1;
private static final int TICK_PER_GENERATE = 5;
private int burnTime = 0;
Expand Down Expand Up @@ -63,7 +63,7 @@ public int size() {
};


public CoalGeneratorBlockEntity() {
public SterlingGeneratorBlockEntity() {
super(VivatechEntities.COAL_GENERATOR);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/vivatech/common/init/VivatechBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import vivatech.common.Vivatech;
import vivatech.common.block.CoalGeneratorBlock;
import vivatech.common.block.SterlingGeneratorBlock;
import vivatech.common.block.CrusherBlock;
import vivatech.common.block.ElectricFurnaceBlock;
import vivatech.common.block.EnergyBankBlock;
Expand All @@ -24,7 +24,7 @@ public class VivatechBlocks {
public static final Block MINIMAL_MACHINE_CHASSIS;
public static final Block NORMAL_MACHINE_CHASSIS;
public static final Block ADVANCED_MACHINE_CHASSIS;
public static final CoalGeneratorBlock COAL_GENERATOR;
public static final SterlingGeneratorBlock COAL_GENERATOR;
public static final EnergyBankBlock ENERGY_BANK;

public static final ImmutableList<CrusherBlock> CRUSHER;
Expand All @@ -36,7 +36,7 @@ public class VivatechBlocks {
MINIMAL_MACHINE_CHASSIS = new Block(FabricBlockSettings.copy(Blocks.STONE).build());
NORMAL_MACHINE_CHASSIS = new Block(FabricBlockSettings.copy(Blocks.IRON_BLOCK).build());
ADVANCED_MACHINE_CHASSIS = new Block(FabricBlockSettings.copy(Blocks.IRON_BLOCK).hardness(7f).resistance(10f).build());
COAL_GENERATOR = new CoalGeneratorBlock();
COAL_GENERATOR = new SterlingGeneratorBlock();
ENERGY_BANK = new EnergyBankBlock();

CRUSHER = TierHelper.fillTieredBlockArray(CrusherBlock::new);
Expand All @@ -49,7 +49,7 @@ public static void initialize() {
Registry.register(Registry.BLOCK, MINIMAL_MACHINE_CHASSIS_ID, MINIMAL_MACHINE_CHASSIS);
Registry.register(Registry.BLOCK, NORMAL_MACHINE_CHASSIS_ID, NORMAL_MACHINE_CHASSIS);
Registry.register(Registry.BLOCK, ADVANCED_MACHINE_CHASSIS_ID, ADVANCED_MACHINE_CHASSIS);
Registry.register(Registry.BLOCK, CoalGeneratorBlock.ID, COAL_GENERATOR);
Registry.register(Registry.BLOCK, SterlingGeneratorBlock.ID, COAL_GENERATOR);
Registry.register(Registry.BLOCK, EnergyBankBlock.ID, ENERGY_BANK);
TierHelper.registerTieredBlocks(CRUSHER);
TierHelper.registerTieredBlocks(ELECTRIC_FURNACE);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/vivatech/common/init/VivatechEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.registry.Registry;
import vivatech.common.block.CoalGeneratorBlock;
import vivatech.common.block.SterlingGeneratorBlock;
import vivatech.common.block.CrusherBlock;
import vivatech.common.block.ElectricFurnaceBlock;
import vivatech.common.block.EnergyBankBlock;
import vivatech.common.block.EnergyConduitBlock;
import vivatech.common.block.PressBlock;
import vivatech.common.block.entity.CoalGeneratorBlockEntity;
import vivatech.common.block.entity.SterlingGeneratorBlockEntity;
import vivatech.common.block.entity.CrusherBlockEntity;
import vivatech.common.block.entity.ElectricFurnaceBlockEntity;
import vivatech.common.block.entity.EnergyBankBlockEntity;
Expand All @@ -18,15 +18,15 @@
import vivatech.api.util.BlockTier;

public class VivatechEntities {
public static final BlockEntityType<CoalGeneratorBlockEntity> COAL_GENERATOR;
public static final BlockEntityType<SterlingGeneratorBlockEntity> COAL_GENERATOR;
public static final BlockEntityType<CrusherBlockEntity> CRUSHER;
public static final BlockEntityType<ElectricFurnaceBlockEntity> ELECTRIC_FURNACE;
public static final BlockEntityType<EnergyBankBlockEntity> ENERGY_BANK;
public static final BlockEntityType<EnergyConduitBlockEntity> ENERGY_CONDUIT;
public static final BlockEntityType<PressBlockEntity> PRESS;

static {
COAL_GENERATOR = BlockEntityType.Builder.create(CoalGeneratorBlockEntity::new,
COAL_GENERATOR = BlockEntityType.Builder.create(SterlingGeneratorBlockEntity::new,
VivatechBlocks.COAL_GENERATOR).build(null);
CRUSHER = BlockEntityType.Builder.create(CrusherBlockEntity::new,
VivatechBlocks.CRUSHER.toArray(new Block[BlockTier.values().length])).build(null);
Expand All @@ -41,7 +41,7 @@ public class VivatechEntities {
}

public static void initialize() {
Registry.register(Registry.BLOCK_ENTITY, CoalGeneratorBlock.ID, COAL_GENERATOR);
Registry.register(Registry.BLOCK_ENTITY, SterlingGeneratorBlock.ID, COAL_GENERATOR);
Registry.register(Registry.BLOCK_ENTITY, CrusherBlock.ID, CRUSHER);
Registry.register(Registry.BLOCK_ENTITY, ElectricFurnaceBlock.ID, ELECTRIC_FURNACE);
Registry.register(Registry.BLOCK_ENTITY, EnergyBankBlock.ID, ENERGY_BANK);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/vivatech/common/init/VivatechItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import net.minecraft.item.Item;
import net.minecraft.util.registry.Registry;
import vivatech.common.Vivatech;
import vivatech.common.block.CoalGeneratorBlock;
import vivatech.common.block.SterlingGeneratorBlock;
import vivatech.common.block.EnergyBankBlock;
import vivatech.common.block.EnergyConduitBlock;
import vivatech.common.item.BatteryItem;
import vivatech.common.item.ScrewdriverItem;
import vivatech.util.TierHelper;
Expand Down Expand Up @@ -46,7 +45,7 @@ public static void initialize() {
Registry.register(Registry.ITEM, VivatechBlocks.MINIMAL_MACHINE_CHASSIS_ID, MINIMAL_MACHINE_CHASSIS);
Registry.register(Registry.ITEM, VivatechBlocks.NORMAL_MACHINE_CHASSIS_ID, NORMAL_MACHINE_CHASSIS);
Registry.register(Registry.ITEM, VivatechBlocks.ADVANCED_MACHINE_CHASSIS_ID, ADVANCED_MACHINE_CHASSIS);
Registry.register(Registry.ITEM, CoalGeneratorBlock.ID, COAL_GENERATOR);
Registry.register(Registry.ITEM, SterlingGeneratorBlock.ID, COAL_GENERATOR);
Registry.register(Registry.ITEM, EnergyBankBlock.ID, ENERGY_BANK);

TierHelper.registerTieredBlockItems(VivatechBlocks.CRUSHER, CRUSHER);
Expand Down
12 changes: 0 additions & 12 deletions src/main/resources/assets/vivatech/blockstates/coal_generator.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"variants": {
"facing=north,active=false": { "model": "vivatech:block/sterling_generator" },
"facing=east,active=false": { "model": "vivatech:block/sterling_generator", "y": 90 },
"facing=south,active=false": { "model": "vivatech:block/sterling_generator", "y": 180 },
"facing=west,active=false": { "model": "vivatech:block/sterling_generator", "y": 270 },
"facing=north,active=true": { "model": "vivatech:block/sterling_generator_active" },
"facing=east,active=true": { "model": "vivatech:block/sterling_generator_active", "y": 90 },
"facing=south,active=true": { "model": "vivatech:block/sterling_generator_active", "y": 180 },
"facing=west,active=true": { "model": "vivatech:block/sterling_generator_active", "y": 270 }
}
}
4 changes: 2 additions & 2 deletions src/main/resources/assets/vivatech/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"block.vivatech.minimal_machine_chassis": "Minimal Machine Chassis",
"block.vivatech.normal_machine_chassis": "Normal Machine Chassis",
"block.vivatech.advanced_machine_chassis": "Advanced Machine Chassis",

"block.vivatech.coal_generator": "Coal Generator",

"block.vivatech.crusher": "Crusher",
"block.vivatech.cutter": "Cutter",
"block.vivatech.electric_furnace": "Electric Furnace",
"block.vivatech.energy_bank": "Energy Bank",
"block.vivatech.energy_conduit": "Energy Conduit",
"block.vivatech.press": "Press",
"block.vivatech.sterling_generator": "Sterling Generator",

"item.vivatech.battery": "Battery",
"item.vivatech.screwdriver": "Screwdriver",
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/assets/vivatech/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"block.vivatech.minimal_machine_chassis": "Минимальный Корпус Машины",
"block.vivatech.normal_machine_chassis": "Обычный Корпус Машины",
"block.vivatech.advanced_machine_chassis": "Продвинутый Корпус Машины",

"block.vivatech.coal_generator": "Угольный Генератор",

"block.vivatech.crusher": "Дробитель",
"block.vivatech.cutter": "Резчик",
"block.vivatech.electric_furnace": "Электропечь",
"block.vivatech.energy_bank": "Энергохранилище",
"block.vivatech.energy_conduit": "Минимальная Труба для Энергии",
"block.vivatech.press": "Пресс",
"block.vivatech.sterling_generator": "Генератор Стерлинга",

"item.vivatech.battery": "Батарея",
"item.vivatech.screwdriver": "Отвёртка",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parent": "vivatech:block/normal_machine_chassis",
"textures": {
"front": "vivatech:block/coal_generator_front"
"front": "vivatech:block/sterling_generator_front"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "vivatech:block/sterling_generator",
"textures": {
"front": "vivatech:block/sterling_generator_active_front"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "vivatech:block/sterling_generator"
}
Loading

0 comments on commit bb39ff4

Please sign in to comment.