Skip to content

Commit

Permalink
bump version to 1.20.6-1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMCCrazyMan committed Jun 16, 2024
1 parent a53bb28 commit d3690a6
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,10 @@
"function": "minecraft:copy_components",
"include": [
"minecraft:container",
"usefulmachinery:contents"
"usefulmachinery:contents",
"usefulmachinery:tier"
],
"source": "block_entity"
},
{
"block": "usefulmachinery:coal_generator",
"conditions": [
{
"condition": "minecraft:inverted",
"term": {
"block": "usefulmachinery:coal_generator",
"condition": "minecraft:block_state_property",
"properties": {
"tier": "simple"
}
}
}
],
"function": "minecraft:copy_state",
"properties": [
"tier"
]
}
],
"name": "usefulmachinery:coal_generator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,10 @@
"include": [
"minecraft:container",
"usefulmachinery:contents",
"usefulmachinery:tier",
"usefulmachinery:mode"
],
"source": "block_entity"
},
{
"block": "usefulmachinery:compactor",
"conditions": [
{
"condition": "minecraft:inverted",
"term": {
"block": "usefulmachinery:compactor",
"condition": "minecraft:block_state_property",
"properties": {
"tier": "simple"
}
}
}
],
"function": "minecraft:copy_state",
"properties": [
"tier"
]
}
],
"name": "usefulmachinery:compactor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,10 @@
"function": "minecraft:copy_components",
"include": [
"minecraft:container",
"usefulmachinery:contents"
"usefulmachinery:contents",
"usefulmachinery:tier"
],
"source": "block_entity"
},
{
"block": "usefulmachinery:crusher",
"conditions": [
{
"condition": "minecraft:inverted",
"term": {
"block": "usefulmachinery:crusher",
"condition": "minecraft:block_state_property",
"properties": {
"tier": "simple"
}
}
}
],
"function": "minecraft:copy_state",
"properties": [
"tier"
]
}
],
"name": "usefulmachinery:crusher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,10 @@
"function": "minecraft:copy_components",
"include": [
"minecraft:container",
"usefulmachinery:contents"
"usefulmachinery:contents",
"usefulmachinery:tier"
],
"source": "block_entity"
},
{
"block": "usefulmachinery:electric_smelter",
"conditions": [
{
"condition": "minecraft:inverted",
"term": {
"block": "usefulmachinery:electric_smelter",
"condition": "minecraft:block_state_property",
"properties": {
"tier": "simple"
}
}
}
],
"function": "minecraft:copy_state",
"properties": [
"tier"
]
}
],
"name": "usefulmachinery:electric_smelter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,10 @@
"include": [
"minecraft:container",
"usefulmachinery:contents",
"usefulmachinery:tier",
"usefulmachinery:tank"
],
"source": "block_entity"
},
{
"block": "usefulmachinery:lava_generator",
"conditions": [
{
"condition": "minecraft:inverted",
"term": {
"block": "usefulmachinery:lava_generator",
"condition": "minecraft:block_state_property",
"properties": {
"tier": "simple"
}
}
}
],
"function": "minecraft:copy_state",
"properties": [
"tier"
]
}
],
"name": "usefulmachinery:lava_generator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponents;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.BlockItemStateProperties;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
Expand All @@ -24,9 +21,7 @@
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.fluids.FluidActionResult;
import net.neoforged.neoforge.fluids.FluidUtil;
Expand All @@ -35,21 +30,19 @@
import net.themcbrothers.lib.wrench.WrenchableBlock;
import net.themcbrothers.usefulmachinery.block.entity.AbstractMachineBlockEntity;
import net.themcbrothers.usefulmachinery.block.entity.LavaGeneratorBlockEntity;
import net.themcbrothers.usefulmachinery.machine.MachineTier;
import org.jetbrains.annotations.Nullable;

import java.util.function.Supplier;

public abstract class AbstractMachineBlock extends BaseEntityBlock implements WrenchableBlock {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final EnumProperty<MachineTier> TIER = EnumProperty.create("tier", MachineTier.class);
public static final BooleanProperty LIT = BlockStateProperties.LIT;
@Nullable
private final Supplier<ResourceLocation> interactStat;

protected AbstractMachineBlock(Properties props, @Nullable Supplier<ResourceLocation> interactStat) {
super(props);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(TIER, MachineTier.SIMPLE).setValue(LIT, Boolean.FALSE));
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(LIT, Boolean.FALSE));
this.interactStat = interactStat;
}

Expand All @@ -59,32 +52,14 @@ protected AbstractMachineBlock(Properties props, @Nullable Supplier<ResourceLoca

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, TIER, LIT);
builder.add(FACING, LIT);
}

@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
}

@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos, Player player) {
ItemStack stack = super.getCloneItemStack(state, target, level, pos, player);

if (level.getBlockEntity(pos) instanceof AbstractMachineBlockEntity blockEntity) {
MachineTier tier = blockEntity.getMachineTier(state);

if (tier != MachineTier.SIMPLE) {
BlockItemStateProperties stateProps = stack.getOrDefault(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY);
stateProps = stateProps.with(TIER, tier);

stack.set(DataComponents.BLOCK_STATE, stateProps);
}
}

return stack;
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemContainerContents;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -34,6 +33,7 @@
import java.util.function.Function;

import static net.themcbrothers.usefulmachinery.core.MachineryDataComponentTypes.CONTENTS;
import static net.themcbrothers.usefulmachinery.core.MachineryDataComponentTypes.TIER;

public abstract class AbstractMachineBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer {
protected static final int ENERGY_CAPACITY = 20_000;
Expand All @@ -46,6 +46,7 @@ public abstract class AbstractMachineBlockEntity extends BaseContainerBlockEntit
protected int processTimeTotal;
protected ExtendedEnergyStorage energyStorage;
protected RedstoneMode redstoneMode = RedstoneMode.IGNORED;
protected MachineTier tier = MachineTier.SIMPLE;

public AbstractMachineBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, boolean isGenerator) {
super(type, pos, state);
Expand Down Expand Up @@ -76,6 +77,9 @@ protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries)
if (this.energyStorage.getEnergyStored() > 0) {
tag.putInt("EnergyStored", this.energyStorage.getEnergyStored());
}
if (this.tier != MachineTier.SIMPLE) {
tag.putInt("Tier", this.tier.ordinal());
}

ContainerHelper.saveAllItems(tag, this.getItems(), false, registries);
}
Expand Down Expand Up @@ -107,6 +111,8 @@ protected void applyImplicitComponents(DataComponentInput input) {
this.processTime = contents.processTime();
this.processTimeTotal = contents.processTimeTotal();
}

this.setMachineTier(input.getOrDefault(TIER.get(), MachineTier.SIMPLE));
}

@Override
Expand All @@ -122,6 +128,7 @@ protected void collectImplicitComponents(DataComponentMap.Builder builder) {
0,
0
));
builder.set(TIER.get(), this.tier);
}

@Override
Expand All @@ -135,6 +142,7 @@ public void removeComponentsFromTag(CompoundTag tag) {
tag.remove("ProcessTimeTotal");
tag.remove("BurnTime");
tag.remove("BurnTimeTotal");
tag.remove("Tier");
}

@Override
Expand All @@ -144,6 +152,7 @@ public void loadAdditional(CompoundTag compound, HolderLookup.Provider registrie
this.redstoneMode = RedstoneMode.byOrdinal(compound.getInt("RedstoneMode"));
this.upgradeContainer = new UpgradeContainer(this.getUpgradeSlotSize());
this.upgradeContainer.fromTag(compound.getList("Upgrades", Tag.TAG_COMPOUND), registries);
this.tier = MachineTier.byOrdinal(compound.getInt("Tier"));

this.initEnergyStorage(compound.getInt("EnergyStored"));

Expand Down Expand Up @@ -237,7 +246,7 @@ protected void initEnergyStorage(int energyStored) {
}

protected int calcProcessTime(int processTime) {
return switch (this.getMachineTier(this.getBlockState())) {
return switch (this.getMachineTier()) {
case SIMPLE -> processTime;
case BASIC -> processTime / 2;
case REINFORCED -> processTime / 4;
Expand All @@ -247,7 +256,7 @@ protected int calcProcessTime(int processTime) {
}

protected int calcBurnTime(int burnTime) {
return (int) switch (this.getMachineTier(this.getBlockState())) {
return (int) switch (this.getMachineTier()) {
case SIMPLE -> burnTime;
case BASIC -> burnTime * 1.2;
case REINFORCED -> burnTime * 1.4;
Expand Down Expand Up @@ -309,7 +318,7 @@ protected boolean isActive(int RFPerTick) {
}

public int getUpgradeSlotSize() {
return this.getMachineTier(this.getBlockState()).ordinal();
return this.getMachineTier().ordinal();
}

public void tick() {
Expand Down Expand Up @@ -380,24 +389,23 @@ public int getProcessTimeTotal() {
return this.processTimeTotal;
}

public MachineTier getMachineTier(BlockState state) {
return state.hasProperty(AbstractMachineBlock.TIER) ? state.getValue(AbstractMachineBlock.TIER) : MachineTier.SIMPLE;
public MachineTier getMachineTier() {
return this.tier;
}

public void setMachineTier(MachineTier machineTier) {
public void setMachineTier(MachineTier tier) {
if (this.level == null) {
return;
}

this.level.setBlock(this.worldPosition, this.getBlockState().setValue(AbstractMachineBlock.TIER, machineTier), Block.UPDATE_ALL);
this.tier = tier;

RegistryAccess registry = this.level.registryAccess();

ListTag previousItems = this.upgradeContainer.createTag(registry);
this.upgradeContainer = new UpgradeContainer(this.getUpgradeSlotSize());
this.upgradeContainer.fromTag(previousItems, registry);


this.initEnergyStorage(this.getEnergyStored());

this.setChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void appendServerData(CompoundTag data, BlockAccessor accessor) {

}

data.putInt("tier", machine.getMachineTier(accessor.getBlockState()).ordinal());
data.putInt("tier", machine.getMachineTier().ordinal());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public void addProbeInfo(ProbeMode probeMode, IProbeInfo probeInfo, Player playe
}

// display tier on upgraded machines
if (machine.getMachineTier(state).ordinal() > 0) {
if (machine.getMachineTier().ordinal() > 0) {
ITextStyle style = probeInfo.defaultTextStyle();

probeInfo.text("Tier: " + machine.getMachineTier(state).getSerializedName(), style);
probeInfo.text("Tier: " + machine.getMachineTier().getSerializedName(), style);
}
}
}
Expand Down
Loading

0 comments on commit d3690a6

Please sign in to comment.