Resin basin finished (Recipe, functionality, textures, models)

This commit is contained in:
Justin Vitale 2020-07-08 01:06:34 +10:00
parent 1c07084416
commit 856f66eeb0
28 changed files with 959 additions and 273 deletions

View file

@ -151,6 +151,7 @@ public class TechRebornClient implements ClientModInitializer {
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.Machine.ALARM.block, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.RUBBER_SAPLING, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.REINFORCED_GLASS, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.Machine.RESIN_BASIN.block, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(TRContent.RUBBER_LEAVES, RenderLayer.getCutoutMipped());

View file

@ -0,0 +1,228 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 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.tier1;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.sound.SoundCategory;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.util.RebornInventory;
import techreborn.blocks.machine.tier1.ResinBasinBlock;
import techreborn.blocks.misc.BlockRubberLog;
import techreborn.config.TechRebornConfig;
import techreborn.init.ModSounds;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import java.util.HashMap;
import java.util.Map;
import static reborncore.api.items.InventoryUtils.getInventoryAt;
public class ResinBasinBlockEntity extends MachineBaseBlockEntity {
private Direction direction = Direction.NORTH;
// State
private boolean isPouring = false;
private boolean isFull = false;
private int pouringTimer = 0;
public ResinBasinBlockEntity() {
super(TRBlockEntities.RESIN_BASIN);
}
@Override
public void tick() {
super.tick();
if(world == null || world.isClient) return;
boolean shouldUpdateState = false;
if(isPouring){
pouringTimer--;
// Play pouring audio
if(world.getTime() % 50 == 0){
world.playSound(pos.getX(),pos.getY(),pos.getZ(), ModSounds.SAP_EXTRACT, SoundCategory.BLOCKS, 0.6F, 1F, false);
}
if(pouringTimer == 0){
isPouring = false;
isFull = true;
shouldUpdateState = true;
}
}
// Try and deposit
if(isFull){
// Find a rubber log
Inventory invBelow = getInventoryBelow();
if(invBelow != null) {
ItemStack out = new ItemStack(TRContent.Parts.SAP, 1);
out = HopperBlockEntity.transfer(null, invBelow, out, Direction.UP);
if (out.isEmpty()) {
// Successfully deposited
isFull = false;
shouldUpdateState = true;
}
}
}
if(!isFull && !isPouring) {
// Check for rubber
if (world.getTime() % TechRebornConfig.checkForSapTime == 0) {
BlockPos targetRubber = getLogWithSap();
if (targetRubber != null){
// We have a valid sap log, harvest it
world.setBlockState(targetRubber, world.getBlockState(targetRubber).with(BlockRubberLog.HAS_SAP, false).with(BlockRubberLog.SAP_SIDE, Direction.fromHorizontal(0)));
isPouring = true;
pouringTimer = TechRebornConfig.sapTimeTicks;
shouldUpdateState = true;
}
}
}
if(shouldUpdateState){
setPouringState(isPouring);
setFullState(isFull);
}
}
@Override
public CompoundTag toTag(CompoundTag tagCompound) {
super.toTag(tagCompound);
tagCompound.putBoolean("isFull", isFull);
return tagCompound;
}
@Override
public void fromTag(BlockState blockState, CompoundTag tagCompound) {
super.fromTag(blockState, tagCompound);
if(tagCompound.contains("isFull")){
this.isFull = tagCompound.getBoolean("isFull");
}
}
@Override
public void onLoad() {
super.onLoad();
if(world == null || world.isClient) return;
// Set facing
direction = world.getBlockState(pos).get(ResinBasinBlock.FACING).getOpposite();
}
private Inventory getInventoryBelow() {
return getInventoryAt(this.getWorld(), this.pos.offset(Direction.DOWN));
}
private BlockPos getLogWithSap(){
// Checking origin block
BlockPos originPos = this.pos.offset(direction);
BlockState originState = world.getBlockState(originPos);
if(originState.getBlock() != TRContent.RUBBER_LOG){
return null;
}
if(originState.get(BlockRubberLog.HAS_SAP)) {
return originPos;
}
boolean shouldExit = false;
BlockPos current = originPos;
// Progress Up
while(!shouldExit){
current = current.offset(Direction.UP);
BlockState state = world.getBlockState(current);
if(state.getBlock() == TRContent.RUBBER_LOG){
if( state.get(BlockRubberLog.HAS_SAP)){
return current;
}
}else{
shouldExit = true;
}
}
current = originPos;
shouldExit = false;
// Progress Down
while(!shouldExit){
current = current.offset(Direction.DOWN);
BlockState state = world.getBlockState(current);
if(state.getBlock() == TRContent.RUBBER_LOG){
if(state.get(BlockRubberLog.HAS_SAP)){
return current;
}
}else{
shouldExit = true;
}
}
// Could not find a rubber log with sap
return null;
}
private void setPouringState(boolean value){
if(world != null){
world.setBlockState(pos, world.getBlockState(pos).with(ResinBasinBlock.POURING, value));
}
}
private void setFullState(boolean value){
if(world != null){
world.setBlockState(pos, world.getBlockState(pos).with(ResinBasinBlock.FULL, value));
}
}
@Override
public boolean hasSlotConfig() {
return false;
}
@Override
public boolean canBeUpgraded() {
return false;
}
}

View file

@ -1,160 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2020 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.tier1;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.Tickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import reborncore.api.items.InventoryBase;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.util.RebornInventory;
import techreborn.blockentity.machine.GenericMachineBlockEntity;
import techreborn.blockentity.machine.misc.ChargeOMatBlockEntity;
import techreborn.blockentity.storage.item.StorageUnitBaseBlockEntity;
import techreborn.blocks.misc.BlockRubberLog;
import techreborn.config.TechRebornConfig;
import techreborn.init.ModSounds;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static reborncore.api.items.InventoryUtils.getInventoryAt;
public class TapperBlockEntity extends MachineBaseBlockEntity {
private static final int OUTPUT_SLOT = 0;
private RebornInventory<TapperBlockEntity> inventory = new RebornInventory<>(1, "TapperBlockEntity", 64, this);
//TODO LIST
// Textures
// Orientable
// States
public TapperBlockEntity() {
super(TRBlockEntities.TAPPER);
}
@Override
public void tick() {
if(world == null || world.isClient) return;
if (world.getTime() % 100 != 0) {
return;
}
BlockPos originPos = this.pos.offset(Direction.NORTH);
BlockState originState = world.getBlockState(originPos);
Inventory invBelow = getInventoryBelow();
if(originState.getBlock() != TRContent.RUBBER_LOG || invBelow == null) return;
HashMap<BlockPos, BlockState> sapLogs = new HashMap<>();
if(originState.get(BlockRubberLog.HAS_SAP)) {
sapLogs.put(originPos, originState);
}
// Get rubber logs with sap above origin
addLogsWithSap(originPos, sapLogs);
// Harvest the sap to inventory, if possible.
if(harvestSap(sapLogs, invBelow)){
world.playSound(pos.getX(),pos.getY(),pos.getZ(), ModSounds.SAP_EXTRACT, SoundCategory.BLOCKS, 0.6F, 1F, false);
}
}
private Inventory getInventoryBelow() {
return getInventoryAt(this.getWorld(), this.pos.offset(Direction.DOWN));
}
private boolean harvestSap(HashMap<BlockPos, BlockState> sapLogs, Inventory invBelow){
// Used for sound
boolean hasSapped = false;
for (Map.Entry<BlockPos, BlockState> entry : sapLogs.entrySet()) {
BlockPos pos = entry.getKey();
BlockState state = entry.getValue();
ItemStack out = new ItemStack(TRContent.Parts.SAP, 1);
out = HopperBlockEntity.transfer(null, invBelow, out, Direction.UP);
if(out.isEmpty()){
world.setBlockState(pos, state.with(BlockRubberLog.HAS_SAP, false).with(BlockRubberLog.SAP_SIDE, Direction.fromHorizontal(0)));
hasSapped = true;
}else{
// Can't deposit into inventory, don't sap
return hasSapped;
}
}
return hasSapped;
}
private void addLogsWithSap(BlockPos originPos, HashMap<BlockPos, BlockState> sapLogs){
boolean shouldExit = false;
BlockPos current = originPos;
// Progress Up (Gravity fed, won't consider sap under current log), origin log has already been checked)
while(!shouldExit){
current = current.offset(Direction.UP);
BlockState state = world.getBlockState(current);
if(state.getBlock() == TRContent.RUBBER_LOG){
if( state.get(BlockRubberLog.HAS_SAP)){
sapLogs.put(current, state);
}
}else{
shouldExit = true;
}
}
}
@Override
public boolean hasSlotConfig() {
return false;
}
@Override
public boolean canBeUpgraded() {
return false;
}
}

View file

@ -0,0 +1,98 @@
package techreborn.blocks.machine.tier1;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blocks.BlockMachineBase;
import techreborn.blocks.GenericMachineBlock;
import techreborn.init.TRContent;
import java.util.function.Supplier;
public class ResinBasinBlock extends BaseBlockEntityProvider {
public static DirectionProperty FACING = Properties.HORIZONTAL_FACING;
public static BooleanProperty POURING = BooleanProperty.of("pouring");
public static BooleanProperty FULL = BooleanProperty.of("full");
Supplier<BlockEntity> blockEntityClass;
public ResinBasinBlock(Supplier<BlockEntity> blockEntityClass) {
super(Block.Settings.of(Material.WOOD).strength(2F, 2F));
this.blockEntityClass = blockEntityClass;
this.setDefaultState(
this.getStateManager().getDefaultState().with(FACING, Direction.NORTH).with(POURING, false).with(FULL, false));
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return VoxelShapes.cuboid(0, 0, 0,1,15/16f,1);
}
public void setFacing(Direction facing, World world, BlockPos pos) {
world.setBlockState(pos, world.getBlockState(pos).with(FACING, facing));
}
// Block
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
FACING = DirectionProperty.of("facing", Direction.Type.HORIZONTAL);
POURING = BooleanProperty.of("pouring");
FULL = BooleanProperty.of("full");
builder.add(FACING, POURING, FULL);
}
public Direction getFacing(BlockState state) {
return state.get(FACING);
}
@Override
public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
super.onPlaced(worldIn, pos, state, placer, stack);
if(worldIn.isClient) return;
Direction facing = placer.getHorizontalFacing().getOpposite();
setFacing(facing, worldIn, pos);
// Drop item if not next to log and yell at user
if(worldIn.getBlockState(pos.offset(facing.getOpposite())).getBlock() != TRContent.RUBBER_LOG){
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
ItemEntity itemEntity = new ItemEntity(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(this.asBlock()));
worldIn.spawnEntity(itemEntity);
placer.sendSystemMessage(new LiteralText(new TranslatableText(this.getTranslationKey()).getString() + new TranslatableText("techreborn.tooltip.invalid_basin_placement").getString()),null);
return;
}
}
@Override
public BlockEntity createBlockEntity(BlockView worldIn) {
if (blockEntityClass == null) {
return null;
}
return blockEntityClass.get();
}
}

View file

@ -1,24 +0,0 @@
package techreborn.blocks.machine.tier1;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import reborncore.api.blockentity.IMachineGuiHandler;
import techreborn.blocks.GenericMachineBlock;
import java.util.function.Supplier;
public class TapperBlock extends GenericMachineBlock {
public TapperBlock(IMachineGuiHandler gui, Supplier<BlockEntity> blockEntityClass) {
super(gui, blockEntityClass);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return VoxelShapes.cuboid(2/16f, 0, 2/16f,14/16f,8/16f,14/16f);
}
}

View file

@ -565,6 +565,12 @@ public class TechRebornConfig {
@Config(config = "misc", category = "nuke", key = "enabled", comment = "Should the nuke explode, set to false to prevent block damage")
public static boolean nukeEnabled = true;
@Config(config = "misc", category = "resin_basin", key = "saptime", comment = "How long it takes to harvest one sap (ticks)")
public static int sapTimeTicks = 80;
@Config(config = "misc", category = "resin_basin", key = "SapCheckTime", comment = "How often to check for sap (will check if world time % this number is zero)")
public static int checkForSapTime = 50;
@Config(config = "misc", category = "general", key = "DispenserScrapbox", comment = "Dispensers will open scrapboxes")
public static boolean dispenseScrapboxes = true;

View file

@ -111,7 +111,7 @@ public class TRBlockEntities {
public static final BlockEntityType<IndustrialSawmillBlockEntity> INDUSTRIAL_SAWMILL = register(IndustrialSawmillBlockEntity::new, "industrial_sawmill", TRContent.Machine.INDUSTRIAL_SAWMILL);
public static final BlockEntityType<SolidFuelGeneratorBlockEntity> SOLID_FUEL_GENEREATOR = register(SolidFuelGeneratorBlockEntity::new, "solid_fuel_generator", TRContent.Machine.SOLID_FUEL_GENERATOR);
public static final BlockEntityType<ExtractorBlockEntity> EXTRACTOR = register(ExtractorBlockEntity::new, "extractor", TRContent.Machine.EXTRACTOR);
public static final BlockEntityType<TapperBlockEntity> TAPPER = register(TapperBlockEntity::new, "tapper", TRContent.Machine.TAPPER);
public static final BlockEntityType<ResinBasinBlockEntity> RESIN_BASIN = register(ResinBasinBlockEntity::new, "resin_basin", TRContent.Machine.RESIN_BASIN);
public static final BlockEntityType<CompressorBlockEntity> COMPRESSOR = register(CompressorBlockEntity::new, "compressor", TRContent.Machine.COMPRESSOR);
public static final BlockEntityType<ElectricFurnaceBlockEntity> ELECTRIC_FURNACE = register(ElectricFurnaceBlockEntity::new, "electric_furnace", TRContent.Machine.ELECTRIC_FURNACE);
public static final BlockEntityType<SolarPanelBlockEntity> SOLAR_PANEL = register(SolarPanelBlockEntity::new, "solar_panel", TRContent.SolarPanels.values());

View file

@ -66,7 +66,7 @@ import techreborn.blocks.lighting.BlockLamp;
import techreborn.blocks.machine.tier0.IronAlloyFurnaceBlock;
import techreborn.blocks.machine.tier0.IronFurnaceBlock;
import techreborn.blocks.machine.tier1.BlockPlayerDetector;
import techreborn.blocks.machine.tier1.TapperBlock;
import techreborn.blocks.machine.tier1.ResinBasinBlock;
import techreborn.blocks.misc.BlockAlarm;
import techreborn.blocks.misc.BlockMachineCasing;
import techreborn.blocks.misc.BlockMachineFrame;
@ -521,7 +521,7 @@ public class TRContent {
COMPRESSOR(new GenericMachineBlock(GuiType.COMPRESSOR, CompressorBlockEntity::new)),
DISTILLATION_TOWER(new GenericMachineBlock(GuiType.DISTILLATION_TOWER, DistillationTowerBlockEntity::new)),
EXTRACTOR(new GenericMachineBlock(GuiType.EXTRACTOR, ExtractorBlockEntity::new)),
TAPPER(new TapperBlock(null, TapperBlockEntity::new)),
RESIN_BASIN(new ResinBasinBlock(ResinBasinBlockEntity::new)),
FLUID_REPLICATOR(new GenericMachineBlock(GuiType.FLUID_REPLICATOR, FluidReplicatorBlockEntity::new)),
GRINDER(new DataDrivenMachineBlock("techreborn:grinder")),
ELECTRIC_FURNACE(new GenericMachineBlock(GuiType.ELECTRIC_FURNACE, ElectricFurnaceBlockEntity::new)),