Skip to content

Commit

Permalink
Update mod to Forge 1.17.1-37.0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
cech12 committed Dec 5, 2021
1 parent 5f4cedc commit 6c75f4f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
package cech12.brickfurnace.tileentity;

import cech12.brickfurnace.config.ServerConfig;
import net.minecraft.block.AbstractFurnaceBlock;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.AbstractCookingRecipe;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.tileentity.AbstractFurnaceTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.math.MathHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractFurnaceBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.AbstractCookingRecipe;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nullable;

public abstract class AbstractBrickFurnaceTileEntity extends AbstractFurnaceTileEntity {
public abstract class AbstractBrickFurnaceTileEntity extends AbstractFurnaceBlockEntity {

protected final IRecipeType<? extends AbstractCookingRecipe> specificRecipeType;
protected final RecipeType<? extends AbstractCookingRecipe> specificRecipeType;
protected final RecipeType<? extends AbstractCookingRecipe> vanillaRecipeType;

public AbstractBrickFurnaceTileEntity(TileEntityType<?> tileTypeIn,
IRecipeType<? extends AbstractCookingRecipe> specificRecipeTypeIn,
IRecipeType<? extends AbstractCookingRecipe> vanillaRecipeTypeIn) {
super(tileTypeIn, vanillaRecipeTypeIn);
public AbstractBrickFurnaceTileEntity(BlockEntityType<?> tileTypeIn,
BlockPos blockPos,
BlockState blockState,
RecipeType<? extends AbstractCookingRecipe> specificRecipeTypeIn,
RecipeType<? extends AbstractCookingRecipe> vanillaRecipeTypeIn) {
super(tileTypeIn, blockPos, blockState, vanillaRecipeTypeIn);
this.specificRecipeType = specificRecipeTypeIn;
this.vanillaRecipeType = vanillaRecipeTypeIn;
}

/* FOLLOWING Code helps the copied code below. */
Expand All @@ -45,63 +52,61 @@ private boolean isBurning() {
return this.dataAccess.get(BURN_TIME) > 0; //changed because of private variable
}

@Override
public void tick() {
boolean wasBurning = this.isBurning();
public static void tick(Level level, BlockPos pos, BlockState state, AbstractBrickFurnaceTileEntity entity) {
boolean wasBurning = entity.isBurning();
boolean dirty = false;
if (this.isBurning()) {
this.dataAccess.set(BURN_TIME, this.dataAccess.get(BURN_TIME) - 1); //changed because of private variable
if (entity.isBurning()) {
entity.dataAccess.set(BURN_TIME, entity.dataAccess.get(BURN_TIME) - 1); //changed because of private variable
}

if (this.level != null && !this.level.isClientSide) {
ItemStack fuel = this.items.get(FUEL);
if (this.isBurning() || !fuel.isEmpty() && !this.items.get(INPUT).isEmpty()) {
AbstractCookingRecipe irecipe = getRecipe();
boolean valid = this.canBurn(irecipe);
if (!this.isBurning() && valid) {
this.dataAccess.set(BURN_TIME, this.getBurnDuration(fuel)); //changed because of private variable
this.dataAccess.set(RECIPES_USED, this.dataAccess.get(BURN_TIME)); //changed because of private variable
if (this.isBurning()) {
if (level != null && !level.isClientSide) {
ItemStack fuel = entity.items.get(FUEL);
if (entity.isBurning() || !fuel.isEmpty() && !entity.items.get(INPUT).isEmpty()) {
AbstractCookingRecipe irecipe = entity.getRecipe();
boolean valid = entity.canBurn(irecipe);
if (!entity.isBurning() && valid) {
entity.dataAccess.set(BURN_TIME, entity.getBurnDuration(fuel)); //changed because of private variable
entity.dataAccess.set(RECIPES_USED, entity.dataAccess.get(BURN_TIME)); //changed because of private variable
if (entity.isBurning()) {
dirty = true;
if (fuel.hasContainerItem()) this.items.set(1, fuel.getContainerItem());
if (fuel.hasContainerItem()) entity.items.set(1, fuel.getContainerItem());
else if (!fuel.isEmpty()) {
fuel.shrink(1);
if (fuel.isEmpty()) {
this.items.set(1, fuel.getContainerItem());
entity.items.set(1, fuel.getContainerItem());
}
}
}
}

if (this.isBurning() && valid) {
this.dataAccess.set(COOK_TIME, this.dataAccess.get(COOK_TIME) + 1); //changed because of private variable
if (this.dataAccess.get(COOK_TIME) == this.dataAccess.get(COOK_TIME_TOTAL)) { //changed because of private variable
this.dataAccess.set(COOK_TIME, 0); //changed because of private variable
this.dataAccess.set(COOK_TIME_TOTAL, this.getTotalCookTime()); //changed because of private variable
this.smeltItem(irecipe);
if (entity.isBurning() && valid) {
entity.dataAccess.set(COOK_TIME, entity.dataAccess.get(COOK_TIME) + 1); //changed because of private variable
if (entity.dataAccess.get(COOK_TIME) == entity.dataAccess.get(COOK_TIME_TOTAL)) { //changed because of private variable
entity.dataAccess.set(COOK_TIME, 0); //changed because of private variable
entity.dataAccess.set(COOK_TIME_TOTAL, entity.getTotalCookTime()); //changed because of private variable
entity.smeltItem(irecipe);
dirty = true;
}
} else {
this.dataAccess.set(COOK_TIME, 0); //changed because of private variable
entity.dataAccess.set(COOK_TIME, 0); //changed because of private variable
}
} else if (!this.isBurning() && this.dataAccess.get(COOK_TIME) > 0) { //changed because of private variable
this.dataAccess.set(COOK_TIME, MathHelper.clamp(this.dataAccess.get(COOK_TIME) - 2, 0, this.dataAccess.get(COOK_TIME_TOTAL))); //changed because of private variable
} else if (!entity.isBurning() && entity.dataAccess.get(COOK_TIME) > 0) { //changed because of private variable
entity.dataAccess.set(COOK_TIME, Mth.clamp(entity.dataAccess.get(COOK_TIME) - 2, 0, entity.dataAccess.get(COOK_TIME_TOTAL))); //changed because of private variable
}

if (wasBurning != this.isBurning()) {
if (wasBurning != entity.isBurning()) {
dirty = true;
this.level.setBlock(this.worldPosition, this.level.getBlockState(this.worldPosition).setValue(AbstractFurnaceBlock.LIT, this.isBurning()), 3);
level.setBlock(pos, state.setValue(AbstractFurnaceBlock.LIT, entity.isBurning()), 3);
}
}

if (dirty) {
this.setChanged();
entity.setChanged();
}

}

@Override
protected boolean canBurn(@Nullable IRecipe<?> recipe) {
private boolean canBurn(@Nullable Recipe<?> recipe) {
if (!this.items.get(0).isEmpty() && recipe != null) {
ItemStack recipeOutput = recipe.getResultItem();
if (!recipeOutput.isEmpty()) {
Expand All @@ -114,7 +119,7 @@ protected boolean canBurn(@Nullable IRecipe<?> recipe) {
return false;
}

private void smeltItem(@Nullable IRecipe<?> recipe) {
private void smeltItem(@Nullable Recipe<?> recipe) {
if (recipe != null && this.canBurn(recipe)) {
ItemStack itemstack = this.items.get(0);
ItemStack itemstack1 = recipe.getResultItem();
Expand All @@ -137,8 +142,7 @@ private void smeltItem(@Nullable IRecipe<?> recipe) {
}
}

@Override
protected int getTotalCookTime() {
private int getTotalCookTime() {
AbstractCookingRecipe rec = getRecipe();
if (rec == null) {
return 200;
Expand All @@ -160,7 +164,7 @@ protected AbstractCookingRecipe getRecipe() {
if (this.level != null) {
rec = this.level.getRecipeManager().getRecipeFor(this.specificRecipeType, this, this.level).orElse(null);
if (rec == null && ServerConfig.VANILLA_RECIPES_ENABLED.get()) {
rec = this.level.getRecipeManager().getRecipesFor(this.recipeType, this, this.level)
rec = this.level.getRecipeManager().getRecipesFor(this.vanillaRecipeType, this, this.level)
.stream().filter(abstractCookingRecipe -> ServerConfig.isRecipeNotBlacklisted(abstractCookingRecipe.getId())).findFirst().orElse(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@

import cech12.brickfurnace.api.crafting.RecipeTypes;
import cech12.brickfurnace.api.tileentity.BrickFurnaceTileEntities;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.BlastFurnaceContainer;
import net.minecraft.inventory.container.Container;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.BlastFurnaceMenu;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nonnull;

public class BrickBlastFurnaceTileEntity extends AbstractBrickFurnaceTileEntity {

public BrickBlastFurnaceTileEntity() {
super(BrickFurnaceTileEntities.BRICK_BLAST_FURNACE, RecipeTypes.BLASTING, IRecipeType.BLASTING);
public BrickBlastFurnaceTileEntity(BlockPos blockPos, BlockState blockState) {
super(BrickFurnaceTileEntities.BRICK_BLAST_FURNACE, blockPos, blockState, RecipeTypes.BLASTING, RecipeType.BLASTING);
}

@Override
@Nonnull
protected ITextComponent getDefaultName() {
return new TranslationTextComponent("block.brickfurnace.brick_blast_furnace");
protected Component getDefaultName() {
return new TranslatableComponent("block.brickfurnace.brick_blast_furnace");
}

@Override
@Nonnull
protected Container createMenu(int id, @Nonnull PlayerInventory player) {
return new BlastFurnaceContainer(id, player, this, this.dataAccess);
protected AbstractContainerMenu createMenu(int id, @Nonnull Inventory player) {
return new BlastFurnaceMenu(id, player, this, this.dataAccess);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@

import cech12.brickfurnace.api.crafting.RecipeTypes;
import cech12.brickfurnace.api.tileentity.BrickFurnaceTileEntities;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.FurnaceContainer;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.FurnaceMenu;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nonnull;

public class BrickFurnaceTileEntity extends AbstractBrickFurnaceTileEntity {

public BrickFurnaceTileEntity() {
super(BrickFurnaceTileEntities.BRICK_FURNACE, RecipeTypes.SMELTING, IRecipeType.SMELTING);
public BrickFurnaceTileEntity(BlockPos blockPos, BlockState blockState) {
super(BrickFurnaceTileEntities.BRICK_FURNACE, blockPos, blockState, RecipeTypes.SMELTING, RecipeType.SMELTING);
}

@Override
@Nonnull
protected ITextComponent getDefaultName() {
return new TranslationTextComponent("block.brickfurnace.brick_furnace");
protected Component getDefaultName() {
return new TranslatableComponent("block.brickfurnace.brick_furnace");
}

@Override
@Nonnull
protected Container createMenu(int id, @Nonnull PlayerInventory player) {
return new FurnaceContainer(id, player, this, this.dataAccess);
protected AbstractContainerMenu createMenu(int id, @Nonnull Inventory player) {
return new FurnaceMenu(id, player, this, this.dataAccess);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@

import cech12.brickfurnace.api.crafting.RecipeTypes;
import cech12.brickfurnace.api.tileentity.BrickFurnaceTileEntities;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.SmokerContainer;
import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.SmokerMenu;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nonnull;

public class BrickSmokerTileEntity extends AbstractBrickFurnaceTileEntity {

public BrickSmokerTileEntity() {
super(BrickFurnaceTileEntities.BRICK_SMOKER, RecipeTypes.SMOKING, IRecipeType.SMOKING);
public BrickSmokerTileEntity(BlockPos blockPos, BlockState blockState) {
super(BrickFurnaceTileEntities.BRICK_SMOKER, blockPos, blockState, RecipeTypes.SMOKING, RecipeType.SMOKING);
}

@Override
@Nonnull
protected ITextComponent getDefaultName() {
return new TranslationTextComponent("block.brickfurnace.brick_smoker");
protected Component getDefaultName() {
return new TranslatableComponent("block.brickfurnace.brick_smoker");
}

@Override
@Nonnull
protected Container createMenu(int id, @Nonnull PlayerInventory player) {
return new SmokerContainer(id, player, this, this.dataAccess);
protected AbstractContainerMenu createMenu(int id, @Nonnull Inventory player) {
return new SmokerMenu(id, player, this, this.dataAccess);
}

}

0 comments on commit 6c75f4f

Please sign in to comment.