Merge remote-tracking branch 'remotes/origin/1.14' into 1.15

# Conflicts:
#	build.gradle
#	src/main/java/techreborn/blocks/misc/BlockRubberLog.java
This commit is contained in:
modmuss50 2019-11-14 19:03:36 +00:00
commit d5e89c5e20
139 changed files with 1534 additions and 501 deletions

View file

@ -1,207 +1,233 @@
package techreborn.blockentity.machine.iron;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.RebornInventory;
import techreborn.config.TechRebornConfig;
public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop {
public RebornInventory<?> inventory;
public int burnTime;
public int totalBurnTime;
public int progress;
public int totalCookingTime;
int fuelSlot;
Block toolDrop;
boolean active = false;
public AbstractIronMachineBlockEntity(BlockEntityType<?> blockEntityTypeIn, int fuelSlot, Block toolDrop) {
super(blockEntityTypeIn);
this.fuelSlot = fuelSlot;
// default value for vanilla smelting recipes is 200
this.totalCookingTime = (int) (200 / TechRebornConfig.cookingScale);
this.toolDrop = toolDrop;
}
/**
* Checks that we have all inputs and can put output into slot
* @return
*/
protected abstract boolean canSmelt();
/**
* Turn ingredients into the appropriate smelted
* item in the output slot
*/
protected abstract void smelt();
/**
* Returns the number of ticks that the supplied fuel item will keep the
* furnace burning, or 0 if the item isn't fuel
* @param stack Itemstack of fuel
* @return Integer Number of ticks
*/
private int getItemBurnTime(ItemStack stack) {
if (stack.isEmpty()) {
return 0;
}
return (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0) * TechRebornConfig.fuelScale);
}
/**
* Returns remaining fraction of fuel burn time
* @param scale Scale to use for burn time
* @return int scaled remaining fuel burn time
*/
public int getBurnTimeRemainingScaled(int scale) {
if (totalBurnTime == 0) {
return 0;
}
return burnTime * scale / totalBurnTime;
}
/**
* Returns crafting progress
* @param scale Scale to use for crafting progress
* @return int Scaled crafting progress
*/
public int getProgressScaled(int scale) {
if (totalCookingTime > 0) {
return progress * scale / totalCookingTime;
}
return 0;
}
/**
* Returns true if Iron Machine is burning fuel thus can do work
* @return Boolean True if machine is burning
*/
public boolean isBurning() {
return burnTime > 0;
}
private void updateState() {
BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock();
if (state.get(BlockMachineBase.ACTIVE) != burnTime > 0)
blockMachineBase.setActive(burnTime > 0, world, pos);
}
}
// MachineBaseBlockEntity
@Override
public void fromTag(CompoundTag compoundTag) {
super.fromTag(compoundTag);
burnTime = compoundTag.getInt("BurnTime");
totalBurnTime = compoundTag.getInt("TotalBurnTime");
progress = compoundTag.getInt("Progress");
}
@Override
public CompoundTag toTag(CompoundTag compoundTag) {
super.toTag(compoundTag);
compoundTag.putInt("BurnTime", burnTime);
compoundTag.putInt("TotalBurnTime", totalBurnTime);
compoundTag.putInt("Progress", progress);
return compoundTag;
}
@Override
public void tick() {
super.tick();
if(world.isClient){
return;
}
boolean isBurning = isBurning();
if (isBurning) {
--burnTime;
}
if (!isBurning && canSmelt()) {
burnTime = totalBurnTime = getItemBurnTime(inventory.getInvStack(fuelSlot));
if (burnTime > 0) {
// Fuel slot
ItemStack fuelStack = inventory.getInvStack(fuelSlot);
if (fuelStack.getItem().hasRecipeRemainder()) {
inventory.setInvStack(fuelSlot, new ItemStack(fuelStack.getItem().getRecipeRemainder()));
} else if (fuelStack.getCount() > 1) {
inventory.shrinkSlot(fuelSlot, 1);
} else if (fuelStack.getCount() == 1) {
inventory.setInvStack(fuelSlot, ItemStack.EMPTY);
}
}
}
if (isBurning() && canSmelt()) {
++progress;
if (progress == totalCookingTime) {
progress = 0;
smelt();
}
} else {
progress = 0;
}
if (isBurning != isBurning()) {
inventory.setChanged();
updateState();
}
if (inventory.hasChanged()) {
markDirty();
}
}
@Override
public boolean canBeUpgraded() {
return false;
}
// InventoryProvider
@Override
public RebornInventory<?> getInventory() {
return inventory;
}
// IToolDrop
@Override
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
return new ItemStack(toolDrop);
}
public int getBurnTime() {
return this.burnTime;
}
public void setBurnTime(int burnTime) {
this.burnTime = burnTime;
}
public int getTotalBurnTime() {
return this.totalBurnTime;
}
public void setTotalBurnTime(int totalBurnTime) {
this.totalBurnTime = totalBurnTime;
}
public int getProgress() {
return progress;
}
public void setProgress(int progress) {
this.progress = progress;
}
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.blockentity.machine.iron;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blockentity.SlotConfiguration;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.RebornInventory;
import techreborn.config.TechRebornConfig;
public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, SlotConfiguration.SlotFilter {
public RebornInventory<?> inventory;
public int burnTime;
public int totalBurnTime;
public int progress;
public int totalCookingTime;
int fuelSlot;
Block toolDrop;
boolean active = false;
public AbstractIronMachineBlockEntity(BlockEntityType<?> blockEntityTypeIn, int fuelSlot, Block toolDrop) {
super(blockEntityTypeIn);
this.fuelSlot = fuelSlot;
// default value for vanilla smelting recipes is 200
this.totalCookingTime = (int) (200 / TechRebornConfig.cookingScale);
this.toolDrop = toolDrop;
}
/**
* Checks that we have all inputs and can put output into slot
* @return
*/
protected abstract boolean canSmelt();
/**
* Turn ingredients into the appropriate smelted
* item in the output slot
*/
protected abstract void smelt();
/**
* Returns the number of ticks that the supplied fuel item will keep the
* furnace burning, or 0 if the item isn't fuel
* @param stack Itemstack of fuel
* @return Integer Number of ticks
*/
private int getItemBurnTime(ItemStack stack) {
if (stack.isEmpty()) {
return 0;
}
return (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0) * TechRebornConfig.fuelScale);
}
/**
* Returns remaining fraction of fuel burn time
* @param scale Scale to use for burn time
* @return int scaled remaining fuel burn time
*/
public int getBurnTimeRemainingScaled(int scale) {
if (totalBurnTime == 0) {
return 0;
}
return burnTime * scale / totalBurnTime;
}
/**
* Returns crafting progress
* @param scale Scale to use for crafting progress
* @return int Scaled crafting progress
*/
public int getProgressScaled(int scale) {
if (totalCookingTime > 0) {
return progress * scale / totalCookingTime;
}
return 0;
}
/**
* Returns true if Iron Machine is burning fuel thus can do work
* @return Boolean True if machine is burning
*/
public boolean isBurning() {
return burnTime > 0;
}
private void updateState() {
BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock();
if (state.get(BlockMachineBase.ACTIVE) != burnTime > 0)
blockMachineBase.setActive(burnTime > 0, world, pos);
}
}
// MachineBaseBlockEntity
@Override
public void fromTag(CompoundTag compoundTag) {
super.fromTag(compoundTag);
burnTime = compoundTag.getInt("BurnTime");
totalBurnTime = compoundTag.getInt("TotalBurnTime");
progress = compoundTag.getInt("Progress");
}
@Override
public CompoundTag toTag(CompoundTag compoundTag) {
super.toTag(compoundTag);
compoundTag.putInt("BurnTime", burnTime);
compoundTag.putInt("TotalBurnTime", totalBurnTime);
compoundTag.putInt("Progress", progress);
return compoundTag;
}
@Override
public void tick() {
super.tick();
if(world.isClient){
return;
}
boolean isBurning = isBurning();
if (isBurning) {
--burnTime;
}
if (!isBurning && canSmelt()) {
burnTime = totalBurnTime = getItemBurnTime(inventory.getInvStack(fuelSlot));
if (burnTime > 0) {
// Fuel slot
ItemStack fuelStack = inventory.getInvStack(fuelSlot);
if (fuelStack.getItem().hasRecipeRemainder()) {
inventory.setInvStack(fuelSlot, new ItemStack(fuelStack.getItem().getRecipeRemainder()));
} else if (fuelStack.getCount() > 1) {
inventory.shrinkSlot(fuelSlot, 1);
} else if (fuelStack.getCount() == 1) {
inventory.setInvStack(fuelSlot, ItemStack.EMPTY);
}
}
}
if (isBurning() && canSmelt()) {
++progress;
if (progress == totalCookingTime) {
progress = 0;
smelt();
}
} else if(!canSmelt()) {
progress = 0;
}
if (isBurning != isBurning()) {
inventory.setChanged();
updateState();
}
if (inventory.hasChanged()) {
markDirty();
}
}
@Override
public boolean canBeUpgraded() {
return false;
}
// InventoryProvider
@Override
public RebornInventory<?> getInventory() {
return inventory;
}
// IToolDrop
@Override
public ItemStack getToolDrop(PlayerEntity entityPlayer) {
return new ItemStack(toolDrop);
}
public int getBurnTime() {
return this.burnTime;
}
public void setBurnTime(int burnTime) {
this.burnTime = burnTime;
}
public int getTotalBurnTime() {
return this.totalBurnTime;
}
public void setTotalBurnTime(int totalBurnTime) {
this.totalBurnTime = totalBurnTime;
}
public int getProgress() {
return progress;
}
public void setProgress(int progress) {
this.progress = progress;
}
}

View file

@ -136,4 +136,17 @@ public class IronAlloyFurnaceBlockEntity extends AbstractIronMachineBlockEntity
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime)
.addInventory().create(this, syncID);
}
@Override
public boolean isStackValid(int slotID, ItemStack stack) {
return ModRecipes.ALLOY_SMELTER.getRecipes(world).stream()
.anyMatch(rebornRecipe -> rebornRecipe.getRebornIngredients().stream()
.anyMatch(rebornIngredient -> rebornIngredient.test(stack))
);
}
@Override
public int[] getInputSlots() {
return new int[]{input1, input2};
}
}

View file

@ -24,8 +24,6 @@
package techreborn.blockentity.machine.iron;
import java.util.Optional;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
@ -41,6 +39,8 @@ import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import techreborn.utils.RecipeUtils;
import java.util.Optional;
public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity implements IContainerProvider {
int inputSlot = 0;
@ -118,7 +118,12 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
int result = inventory.getInvStack(outputSlot).getCount() + outputStack.getCount();
return result <= inventory.getStackLimit() && result <= outputStack.getMaxCount();
}
@Override
public boolean isStackValid(int slotID, ItemStack stack) {
return !getResultFor(stack).isEmpty();
}
@Override
public void fromTag(CompoundTag compoundTag) {
super.fromTag(compoundTag);
@ -141,6 +146,11 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
this.experience = experience;
}
@Override
public int[] getInputSlots() {
return new int[]{inputSlot};
}
@Override
public BuiltContainer createContainer(int syncID, final PlayerEntity player) {
return new ContainerBuilder("ironfurnace").player(player.inventory).inventory().hotbar()

View file

@ -30,6 +30,7 @@ import net.minecraft.util.math.BlockPos;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.crafting.RebornRecipe;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory;
import techreborn.blockentity.GenericMachineBlockEntity;
@ -40,8 +41,6 @@ import techreborn.init.TRContent;
public class DistillationTowerBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
public MultiblockChecker multiblockChecker;
public DistillationTowerBlockEntity() {
@ -74,10 +73,8 @@ public class DistillationTowerBlockEntity extends GenericMachineBlockEntity impl
final BlockPos downCenter = pos.method_10079(getFacing().getOpposite(), 2);
multiblockChecker = new MultiblockChecker(world, downCenter);
}
if (!world.isClient && getMutliBlock()){
super.tick();
}
super.tick();
}
// IContainerProvider
@ -88,4 +85,9 @@ public class DistillationTowerBlockEntity extends GenericMachineBlockEntity impl
.outputSlot(4, 119, 37).outputSlot(5, 139, 37).energySlot(6, 8, 72).syncEnergyValue().syncCrafterValue()
.addInventory().create(this, syncID);
}
@Override
public boolean canCraft(RebornRecipe rebornRecipe) {
return getMutliBlock();
}
}

View file

@ -29,13 +29,14 @@ import net.minecraft.util.math.BlockPos;
import reborncore.client.containerBuilder.IContainerProvider;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder;
import reborncore.common.crafting.RebornRecipe;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory;
import techreborn.blockentity.GenericMachineBlockEntity;
import techreborn.config.TechRebornConfig;
import techreborn.init.ModRecipes;
import techreborn.init.TRContent;
import techreborn.init.TRBlockEntities;
import techreborn.blockentity.GenericMachineBlockEntity;
import techreborn.init.TRContent;
public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity implements IContainerProvider {
@ -65,10 +66,8 @@ public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity im
if (multiblockChecker == null) {
multiblockChecker = new MultiblockChecker(world, pos.down(3));
}
if (!world.isClient && getMutliBlock()){
super.tick();
}
super.tick();
}
// IContainerProvider
@ -78,4 +77,9 @@ public class ImplosionCompressorBlockEntity extends GenericMachineBlockEntity im
.blockEntity(this).slot(0, 50, 27).slot(1, 50, 47).outputSlot(2, 92, 36).outputSlot(3, 110, 36)
.energySlot(4, 8, 72).syncEnergyValue().syncCrafterValue().addInventory().create(this, syncID);
}
@Override
public boolean canCraft(RebornRecipe rebornRecipe) {
return getMutliBlock();
}
}