Compiler Fixes for EndStoneSmelter
This commit is contained in:
parent
09a19845a4
commit
08fc14439a
2 changed files with 52 additions and 50 deletions
|
@ -1,10 +1,6 @@
|
||||||
package ru.betterend.blocks;
|
package ru.betterend.blocks;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
|
@ -21,13 +17,10 @@ import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.*;
|
||||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
|
||||||
import net.minecraft.world.level.block.Mirror;
|
|
||||||
import net.minecraft.world.level.block.RenderShape;
|
|
||||||
import net.minecraft.world.level.block.Rotation;
|
|
||||||
import net.minecraft.world.level.block.SoundType;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.StateDefinition;
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
|
@ -38,8 +31,13 @@ import net.minecraft.world.level.material.MaterialColor;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.bclib.blocks.BaseBlockWithEntity;
|
import ru.bclib.blocks.BaseBlockWithEntity;
|
||||||
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
|
import ru.betterend.blocks.entities.EndStoneSmelterBlockEntity;
|
||||||
|
import ru.betterend.registry.EndBlockEntities;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class EndStoneSmelter extends BaseBlockWithEntity {
|
public class EndStoneSmelter extends BaseBlockWithEntity {
|
||||||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
||||||
|
@ -79,8 +77,8 @@ public class EndStoneSmelter extends BaseBlockWithEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity newBlockEntity(BlockGetter world) {
|
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||||
return new EndStoneSmelterBlockEntity();
|
return new EndStoneSmelterBlockEntity(blockPos, blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,4 +147,10 @@ public class EndStoneSmelter extends BaseBlockWithEntity {
|
||||||
world.addParticle(ParticleTypes.SMOKE, x + offX, y + offY, z + offZ, 0.0D, 0.0D, 0.0D);
|
world.addParticle(ParticleTypes.SMOKE, x + offX, y + offY, z + offZ, 0.0D, 0.0D, 0.0D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockEntityType<T> blockEntityType) {
|
||||||
|
return level.isClientSide() ? null : createTickerHelper(blockEntityType, EndBlockEntities.END_STONE_SMELTER, EndStoneSmelterBlockEntity::tick);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
package ru.betterend.blocks.entities;
|
package ru.betterend.blocks.entities;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
|
import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
import net.fabricmc.fabric.api.registry.FuelRegistry;
|
import net.fabricmc.fabric.api.registry.FuelRegistry;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.NonNullList;
|
import net.minecraft.core.NonNullList;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
@ -37,7 +33,6 @@ import net.minecraft.world.level.ItemLike;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.TickableBlockEntity;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
|
@ -46,7 +41,11 @@ import ru.betterend.client.gui.EndStoneSmelterScreenHandler;
|
||||||
import ru.betterend.recipe.builders.AlloyingRecipe;
|
import ru.betterend.recipe.builders.AlloyingRecipe;
|
||||||
import ru.betterend.registry.EndBlockEntities;
|
import ru.betterend.registry.EndBlockEntities;
|
||||||
|
|
||||||
public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder, StackedContentsCompatible, TickableBlockEntity {
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder, StackedContentsCompatible {
|
||||||
|
|
||||||
private static final int[] TOP_SLOTS = new int[] { 0, 1 };
|
private static final int[] TOP_SLOTS = new int[] { 0, 1 };
|
||||||
private static final int[] BOTTOM_SLOTS = new int[] { 2, 3 };
|
private static final int[] BOTTOM_SLOTS = new int[] { 2, 3 };
|
||||||
|
@ -62,8 +61,8 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
||||||
private int burnTime;
|
private int burnTime;
|
||||||
private int fuelTime;
|
private int fuelTime;
|
||||||
|
|
||||||
public EndStoneSmelterBlockEntity() {
|
public EndStoneSmelterBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||||
super(EndBlockEntities.END_STONE_SMELTER);
|
super(EndBlockEntities.END_STONE_SMELTER, blockPos, blockState);
|
||||||
this.inventory = NonNullList.withSize(4, ItemStack.EMPTY);
|
this.inventory = NonNullList.withSize(4, ItemStack.EMPTY);
|
||||||
this.recipesUsed = new Object2IntOpenHashMap<>();
|
this.recipesUsed = new Object2IntOpenHashMap<>();
|
||||||
this.propertyDelegate = new ContainerData() {
|
this.propertyDelegate = new ContainerData() {
|
||||||
|
@ -225,61 +224,60 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
||||||
return new EndStoneSmelterScreenHandler(syncId, playerInventory, this, propertyDelegate);
|
return new EndStoneSmelterScreenHandler(syncId, playerInventory, this, propertyDelegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static void tick(Level tickLevel, BlockPos tickPos, BlockState tickState, EndStoneSmelterBlockEntity blockEntity) {
|
||||||
public void tick() {
|
if (tickLevel == null) return;
|
||||||
if (level == null) return;
|
|
||||||
|
|
||||||
boolean initialBurning = isBurning();
|
boolean initialBurning = blockEntity.isBurning();
|
||||||
if (initialBurning) {
|
if (initialBurning) {
|
||||||
burnTime--;
|
blockEntity.burnTime--;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean burning = initialBurning;
|
boolean burning = initialBurning;
|
||||||
if (!level.isClientSide) {
|
if (!tickLevel.isClientSide) {
|
||||||
ItemStack fuel = inventory.get(2);
|
ItemStack fuel = blockEntity.inventory.get(2);
|
||||||
if (!burning && (fuel.isEmpty() || inventory.get(0).isEmpty() && inventory.get(1).isEmpty())) {
|
if (!burning && (fuel.isEmpty() || blockEntity.inventory.get(0).isEmpty() && blockEntity.inventory.get(1).isEmpty())) {
|
||||||
if (smeltTime > 0) {
|
if (blockEntity.smeltTime > 0) {
|
||||||
smeltTime = Mth.clamp(smeltTime - 2, 0, smeltTimeTotal);
|
blockEntity.smeltTime = Mth.clamp(blockEntity.smeltTime - 2, 0, blockEntity.smeltTimeTotal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Recipe<?> recipe = level.getRecipeManager().getRecipeFor(AlloyingRecipe.TYPE, this, level).orElse(null);
|
Recipe<?> recipe = tickLevel.getRecipeManager().getRecipeFor(AlloyingRecipe.TYPE, blockEntity, tickLevel).orElse(null);
|
||||||
if (recipe == null) {
|
if (recipe == null) {
|
||||||
recipe = level.getRecipeManager().getRecipeFor(RecipeType.BLASTING, this, level).orElse(null);
|
recipe = tickLevel.getRecipeManager().getRecipeFor(RecipeType.BLASTING, blockEntity, tickLevel).orElse(null);
|
||||||
}
|
}
|
||||||
boolean accepted = this.canAcceptRecipeOutput(recipe);
|
boolean accepted = blockEntity.canAcceptRecipeOutput(recipe);
|
||||||
if (!burning && accepted) {
|
if (!burning && accepted) {
|
||||||
burnTime = getFuelTime(fuel);
|
blockEntity.burnTime = blockEntity.getFuelTime(fuel);
|
||||||
fuelTime = burnTime;
|
blockEntity.fuelTime = blockEntity.burnTime;
|
||||||
burning = isBurning();
|
burning = blockEntity.isBurning();
|
||||||
if (burning) {
|
if (burning) {
|
||||||
if (!fuel.isEmpty()) {
|
if (!fuel.isEmpty()) {
|
||||||
Item item = fuel.getItem();
|
Item item = fuel.getItem();
|
||||||
fuel.shrink(1);
|
fuel.shrink(1);
|
||||||
if (fuel.isEmpty()) {
|
if (fuel.isEmpty()) {
|
||||||
Item remainFuel = item.getCraftingRemainingItem();
|
Item remainFuel = item.getCraftingRemainingItem();
|
||||||
inventory.set(2, remainFuel == null ? ItemStack.EMPTY : new ItemStack(remainFuel));
|
blockEntity.inventory.set(2, remainFuel == null ? ItemStack.EMPTY : new ItemStack(remainFuel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setChanged();
|
blockEntity.setChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (burning && accepted) {
|
if (burning && accepted) {
|
||||||
this.smeltTime++;
|
blockEntity.smeltTime++;
|
||||||
if (smeltTime == smeltTimeTotal) {
|
if (blockEntity.smeltTime == blockEntity.smeltTimeTotal) {
|
||||||
smeltTime = 0;
|
blockEntity.smeltTime = 0;
|
||||||
smeltTimeTotal = getSmeltTime();
|
blockEntity.smeltTimeTotal = blockEntity.getSmeltTime();
|
||||||
craftRecipe(recipe);
|
blockEntity.craftRecipe(recipe);
|
||||||
setChanged();
|
blockEntity.setChanged();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
smeltTime = 0;
|
blockEntity.smeltTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialBurning != burning) {
|
if (initialBurning != burning) {
|
||||||
level.setBlock(worldPosition, level.getBlockState(worldPosition).setValue(EndStoneSmelter.LIT, burning), 3);
|
tickLevel.setBlock(tickPos, tickState.setValue(EndStoneSmelter.LIT, burning), 3);
|
||||||
setChanged();
|
blockEntity.setChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,8 +393,8 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(BlockState state, CompoundTag tag) {
|
public void load(CompoundTag tag) {
|
||||||
super.load(state, tag);
|
super.load(tag);
|
||||||
inventory = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY);
|
inventory = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY);
|
||||||
ContainerHelper.loadAllItems(tag, inventory);
|
ContainerHelper.loadAllItems(tag, inventory);
|
||||||
burnTime = tag.getShort("BurnTime");
|
burnTime = tag.getShort("BurnTime");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue