Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
some classes were renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
anviaan committed Jul 25, 2023
1 parent ac89f92 commit af4872e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/anvian/perfume/block/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.anvian.perfume.block;

import net.anvian.perfume.PerfumeMod;
import net.anvian.perfume.block.custom.CustomMesa;
import net.anvian.perfume.block.custom.CustomPerfumeMachine;
import net.anvian.perfume.item.ModItemGroup;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
Expand All @@ -14,7 +14,7 @@

public class ModBlocks {
public static final Block PERFUME_MACHINE = registerBlock("perfume_machine",
new CustomMesa(FabricBlockSettings.of(Material.METAL)));
new CustomPerfumeMachine(FabricBlockSettings.of(Material.METAL)));

private static Block registerBlock(String name, Block block){
registerBlockItem(name, block);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.anvian.perfume.block.custom;

import net.anvian.perfume.block.entity.MesaBlockEntity;
import net.anvian.perfume.block.entity.PerfumeMachineBlockEntity;
import net.anvian.perfume.block.entity.ModBlockEntities;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
Expand All @@ -16,17 +16,17 @@
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public class CustomMesa extends BlockWithEntity implements BlockEntityProvider {
public CustomMesa(Settings settings) {
public class CustomPerfumeMachine extends BlockWithEntity implements BlockEntityProvider {
public CustomPerfumeMachine(Settings settings) {
super(settings);
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock() != newState.getBlock()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof MesaBlockEntity) {
ItemScatterer.spawn(world, pos, (MesaBlockEntity)blockEntity);
if (blockEntity instanceof PerfumeMachineBlockEntity) {
ItemScatterer.spawn(world, pos, (PerfumeMachineBlockEntity)blockEntity);
world.updateComparators(pos,this);
}
super.onStateReplaced(state, world, pos, newState, moved);
Expand Down Expand Up @@ -55,12 +55,12 @@ public BlockRenderType getRenderType(BlockState state) {
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new MesaBlockEntity(pos, state);
return new PerfumeMachineBlockEntity(pos, state);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return checkType(type, ModBlockEntities.MESA, MesaBlockEntity::tick);
return checkType(type, ModBlockEntities.PERFUME_MACHINE, PerfumeMachineBlockEntity::tick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import net.minecraft.util.registry.Registry;

public class ModBlockEntities {
public static BlockEntityType<MesaBlockEntity> MESA;
public static BlockEntityType<PerfumeMachineBlockEntity> PERFUME_MACHINE;

public static void registerAllBlockEntities() {
MESA = Registry.register(Registry.BLOCK_ENTITY_TYPE,
PERFUME_MACHINE = Registry.register(Registry.BLOCK_ENTITY_TYPE,
new Identifier(PerfumeMod.MOD_ID, "mesa"),
FabricBlockEntityTypeBuilder.create(MesaBlockEntity::new,
FabricBlockEntityTypeBuilder.create(PerfumeMachineBlockEntity::new,
ModBlocks.PERFUME_MACHINE).build(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import java.util.Optional;

public class MesaBlockEntity extends BlockEntity implements NamedScreenHandlerFactory, ImplementedInventory {
public class PerfumeMachineBlockEntity extends BlockEntity implements NamedScreenHandlerFactory, ImplementedInventory {

private final DefaultedList<ItemStack> inventory =
DefaultedList.ofSize(4, ItemStack.EMPTY);
Expand All @@ -33,25 +33,25 @@ public class MesaBlockEntity extends BlockEntity implements NamedScreenHandlerFa
private int fuelTime = 0;
private int maxFuelTime = 0;

public MesaBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.MESA, pos, state);
public PerfumeMachineBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.PERFUME_MACHINE, pos, state);
this.propertyDelegate = new PropertyDelegate() {
public int get(int index) {
return switch (index) {
case 0 -> MesaBlockEntity.this.progress;
case 1 -> MesaBlockEntity.this.maxProgress;
case 2 -> MesaBlockEntity.this.fuelTime;
case 3 -> MesaBlockEntity.this.maxFuelTime;
case 0 -> PerfumeMachineBlockEntity.this.progress;
case 1 -> PerfumeMachineBlockEntity.this.maxProgress;
case 2 -> PerfumeMachineBlockEntity.this.fuelTime;
case 3 -> PerfumeMachineBlockEntity.this.maxFuelTime;
default -> 0;
};
}

public void set(int index, int value) {
switch (index) {
case 0 -> MesaBlockEntity.this.progress = value;
case 1 -> MesaBlockEntity.this.maxProgress = value;
case 2 -> MesaBlockEntity.this.fuelTime = value;
case 3 -> MesaBlockEntity.this.maxFuelTime = value;
case 0 -> PerfumeMachineBlockEntity.this.progress = value;
case 1 -> PerfumeMachineBlockEntity.this.maxProgress = value;
case 2 -> PerfumeMachineBlockEntity.this.fuelTime = value;
case 3 -> PerfumeMachineBlockEntity.this.maxFuelTime = value;
}
}

Expand All @@ -68,7 +68,7 @@ public DefaultedList<ItemStack> getItems() {

@Override
public Text getDisplayName() {
return Text.literal("Mesa Entity");
return Text.translatable("blockEntity.perfume_machine");
}

@Nullable
Expand All @@ -95,15 +95,15 @@ public void readNbt(NbtCompound nbt) {
maxFuelTime = nbt.getInt("mesa.maxFuelTime");
}

private void consumeFuel(MesaBlockEntity entity) {
private void consumeFuel(PerfumeMachineBlockEntity entity) {
if(!getStack(0).isEmpty()) {
this.fuelTime = 50;
this.maxFuelTime = this.fuelTime;
entity.removeStack(0,1);
}
}

public static void tick(World world, BlockPos pos, BlockState state, MesaBlockEntity entity) {
public static void tick(World world, BlockPos pos, BlockState state, PerfumeMachineBlockEntity entity) {
if(isConsumingFuel(entity)) {
entity.fuelTime--;
}
Expand All @@ -123,15 +123,15 @@ public static void tick(World world, BlockPos pos, BlockState state, MesaBlockEn
}
}

private static boolean hasFuelInFuelSlot(MesaBlockEntity entity) {
private static boolean hasFuelInFuelSlot(PerfumeMachineBlockEntity entity) {
return !entity.getStack(0).isEmpty();
}

private static boolean isConsumingFuel(MesaBlockEntity entity) {
private static boolean isConsumingFuel(PerfumeMachineBlockEntity entity) {
return entity.fuelTime > 0;
}

private static boolean hasRecipe(MesaBlockEntity entity) {
private static boolean hasRecipe(PerfumeMachineBlockEntity entity) {
World world = entity.world;
SimpleInventory inventory = new SimpleInventory(entity.inventory.size());
for (int i = 0; i < entity.inventory.size(); i++) {
Expand All @@ -145,7 +145,7 @@ private static boolean hasRecipe(MesaBlockEntity entity) {
&& canInsertItemIntoOutputSlot(inventory, match.get().getOutput());
}

private static void craftItem(MesaBlockEntity entity) {
private static void craftItem(PerfumeMachineBlockEntity entity) {
World world = entity.world;
SimpleInventory inventory = new SimpleInventory(entity.inventory.size());
for (int i = 0; i < entity.inventory.size(); i++) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/perfume/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"item.perfume.water_perfume_bottle" : "Water glass perfume bottle",

"block.perfume.perfume_machine" : "Perfume machine",
"blockEntity.perfume_machine" : "Perfume machine",

"item.perfume.carrot_perfume" : "Carrot perfume",
"effect.perfume.carrot_effect": "Carrot perfume",
Expand Down

0 comments on commit af4872e

Please sign in to comment.