2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("BlockCompost.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
2015-02-09 17:25:05 +01:00
|
|
|
|
2021-02-27 21:24:26 +01:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2016-05-20 17:55:33 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
2016-08-02 16:32:13 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
2016-11-16 16:59:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.block.SoundType;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2018-06-24 02:44:47 +02:00
|
|
|
import net.minecraft.block.properties.IProperty;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2021-02-27 17:22:03 +01:00
|
|
|
import net.minecraft.client.MainWindow;
|
2015-12-22 00:04:48 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2015-03-07 02:23:31 +01:00
|
|
|
import net.minecraft.item.EnumRarity;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2018-06-24 02:44:47 +02:00
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.util.Direction;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.util.Hand;
|
2016-05-02 17:09:23 +02:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2016-05-02 17:09:23 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.world.World;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
2018-06-24 02:44:47 +02:00
|
|
|
import net.minecraftforge.common.property.ExtendedBlockState;
|
|
|
|
import net.minecraftforge.common.property.IExtendedBlockState;
|
|
|
|
import net.minecraftforge.common.property.IUnlistedProperty;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.OnlyIn;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
|
|
|
import java.util.List;
|
2015-02-09 17:25:05 +01:00
|
|
|
|
2018-06-24 02:44:47 +02:00
|
|
|
public class BlockCompost extends BlockContainerBase implements IHudDisplay {
|
2015-02-09 17:25:05 +01:00
|
|
|
|
2016-05-02 17:09:23 +02:00
|
|
|
protected static final AxisAlignedBB AABB_LEGS = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.3125D, 1.0D);
|
|
|
|
protected static final AxisAlignedBB AABB_WALL_NORTH = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D);
|
|
|
|
protected static final AxisAlignedBB AABB_WALL_SOUTH = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D);
|
|
|
|
protected static final AxisAlignedBB AABB_WALL_EAST = new AxisAlignedBB(0.875D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
|
|
|
|
protected static final AxisAlignedBB AABB_WALL_WEST = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.125D, 1.0D, 1.0D);
|
2018-06-24 02:44:47 +02:00
|
|
|
private static final AxisAlignedBB AABB = new AxisAlignedBB(0.0625, 0, 0.0625, 1 - 0.0625, 11 * 0.0625, 1 - 0.0625);
|
2016-05-02 17:09:23 +02:00
|
|
|
|
2021-02-27 13:24:45 +01:00
|
|
|
public BlockCompost() {
|
|
|
|
super(Material.WOOD);
|
2015-02-09 17:25:05 +01:00
|
|
|
this.setHarvestLevel("axe", 0);
|
2015-07-07 01:13:39 +02:00
|
|
|
this.setHardness(0.5F);
|
|
|
|
this.setResistance(5.0F);
|
2016-04-20 21:39:03 +02:00
|
|
|
this.setSoundType(SoundType.WOOD);
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
|
|
|
|
2016-05-02 17:09:23 +02:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public AxisAlignedBB getBoundingBox(BlockState state, IBlockAccess source, BlockPos pos) {
|
2016-05-02 17:09:23 +02:00
|
|
|
return AABB;
|
2016-03-18 23:47:22 +01:00
|
|
|
}
|
2016-05-02 17:09:23 +02:00
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
2018-08-04 04:22:20 +02:00
|
|
|
@Deprecated
|
2021-02-26 22:15:48 +01:00
|
|
|
public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean someBool) {
|
|
|
|
this.addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_LEGS);
|
|
|
|
this.addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_WEST);
|
|
|
|
this.addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_NORTH);
|
|
|
|
this.addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_EAST);
|
|
|
|
this.addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_SOUTH);
|
2016-05-02 17:09:23 +02:00
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public boolean isOpaqueCube(BlockState state) {
|
2015-10-03 10:19:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-20 15:23:03 +01:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public boolean isFullCube(BlockState state) {
|
2016-02-20 15:23:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2021-02-27 13:24:45 +01:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, BlockState state, PlayerEntity player, Hand hand, Direction f6, float f7, float f8, float f9) {
|
2016-11-19 21:11:17 +01:00
|
|
|
ItemStack stackPlayer = player.getHeldItem(hand);
|
2018-06-24 02:44:47 +02:00
|
|
|
if (!world.isRemote) {
|
2016-05-20 17:55:33 +02:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
2018-06-24 02:44:47 +02:00
|
|
|
if (tile instanceof TileEntityCompost) {
|
|
|
|
TileEntityCompost compost = (TileEntityCompost) tile;
|
2018-06-23 01:39:30 +02:00
|
|
|
ItemStack slot = compost.inv.getStackInSlot(0);
|
2016-05-20 17:55:33 +02:00
|
|
|
CompostRecipe recipeIn = TileEntityCompost.getRecipeForInput(slot);
|
2018-06-24 02:44:47 +02:00
|
|
|
if (!StackUtil.isValid(slot) || recipeIn != null) {
|
|
|
|
if (StackUtil.isValid(stackPlayer)) {
|
2016-05-20 17:55:33 +02:00
|
|
|
CompostRecipe recipeHand = TileEntityCompost.getRecipeForInput(stackPlayer);
|
2018-06-24 02:44:47 +02:00
|
|
|
if (recipeHand != null && (recipeIn == null || recipeIn == recipeHand)) {
|
2018-06-23 01:39:30 +02:00
|
|
|
int maxAdd = stackPlayer.getCount();
|
2016-05-20 17:55:33 +02:00
|
|
|
|
2018-06-24 02:44:47 +02:00
|
|
|
if (!StackUtil.isValid(slot)) {
|
2016-05-20 17:55:33 +02:00
|
|
|
ItemStack stackToAdd = stackPlayer.copy();
|
2018-06-23 01:39:30 +02:00
|
|
|
stackToAdd.setCount(maxAdd);
|
|
|
|
compost.inv.setStackInSlot(0, stackToAdd);
|
2016-05-20 17:55:33 +02:00
|
|
|
player.inventory.decrStackSize(player.inventory.currentItem, maxAdd);
|
|
|
|
return true;
|
2018-06-24 02:44:47 +02:00
|
|
|
} else {
|
2016-05-20 17:55:33 +02:00
|
|
|
ItemStack stackIn = slot.copy();
|
2018-06-24 02:44:47 +02:00
|
|
|
if (stackIn.getCount() < slot.getMaxStackSize()) {
|
|
|
|
int sizeAdded = Math.min(maxAdd, slot.getMaxStackSize() - stackIn.getCount());
|
2018-06-23 01:39:30 +02:00
|
|
|
stackIn.grow(sizeAdded);
|
|
|
|
compost.inv.setStackInSlot(0, stackIn);
|
2016-05-20 17:55:33 +02:00
|
|
|
player.inventory.decrStackSize(player.inventory.currentItem, sizeAdded);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-19 20:05:12 +02:00
|
|
|
}
|
2018-06-24 02:44:47 +02:00
|
|
|
} else {
|
|
|
|
if (!StackUtil.isValid(stackPlayer)) {
|
2016-11-17 16:31:05 +01:00
|
|
|
player.setHeldItem(hand, slot.copy());
|
2018-06-23 01:39:30 +02:00
|
|
|
compost.inv.setStackInSlot(0, StackUtil.getEmpty());
|
2016-05-20 17:55:33 +02:00
|
|
|
return true;
|
2018-06-24 02:44:47 +02:00
|
|
|
} else if (ItemUtil.canBeStacked(stackPlayer, slot)) {
|
|
|
|
int addedStackSize = Math.min(slot.getCount(), stackPlayer.getMaxStackSize() - stackPlayer.getCount());
|
2016-05-20 17:55:33 +02:00
|
|
|
ItemStack stackToAdd = stackPlayer.copy();
|
2018-06-23 01:39:30 +02:00
|
|
|
stackToAdd.grow(addedStackSize);
|
2016-11-17 16:31:05 +01:00
|
|
|
player.setHeldItem(hand, stackToAdd);
|
2018-06-23 01:39:30 +02:00
|
|
|
compost.inv.getStackInSlot(0).shrink(addedStackSize);
|
2016-05-20 17:55:33 +02:00
|
|
|
return true;
|
|
|
|
|
2016-05-19 20:05:12 +02:00
|
|
|
}
|
2015-10-02 16:48:01 +02:00
|
|
|
}
|
2018-06-24 02:44:47 +02:00
|
|
|
tile.markDirty();
|
2019-02-27 19:53:05 +01:00
|
|
|
world.notifyBlockUpdate(pos, this.getDefaultState(), this.getDefaultState(), 3);
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
2018-06-24 02:44:47 +02:00
|
|
|
} else {
|
2016-05-20 17:55:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2018-06-24 02:44:47 +02:00
|
|
|
public TileEntity createNewTileEntity(World world, int meta) {
|
2015-02-09 17:25:05 +01:00
|
|
|
return new TileEntityCompost();
|
|
|
|
}
|
2015-02-17 16:15:16 +01:00
|
|
|
|
2015-10-23 16:48:56 +02:00
|
|
|
@Override
|
2018-06-24 02:44:47 +02:00
|
|
|
public EnumRarity getRarity(ItemStack stack) {
|
2016-01-07 21:41:28 +01:00
|
|
|
return EnumRarity.UNCOMMON;
|
2015-03-07 02:23:31 +01:00
|
|
|
}
|
2015-12-22 00:04:48 +01:00
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2021-02-27 21:24:26 +01:00
|
|
|
public void displayHud(MatrixStack matrices, Minecraft minecraft, PlayerEntity player, ItemStack stack, RayTraceResult rayCast, MainWindow resolution) {
|
|
|
|
TileEntity tile = minecraft.world.getTileEntity(rayCast.getBlockPos());
|
2018-06-24 02:44:47 +02:00
|
|
|
if (tile instanceof TileEntityCompost) {
|
|
|
|
ItemStack slot = ((TileEntityCompost) tile).inv.getStackInSlot(0);
|
2015-12-22 00:04:48 +01:00
|
|
|
String strg;
|
2018-06-24 02:44:47 +02:00
|
|
|
if (!StackUtil.isValid(slot)) {
|
2015-12-22 00:04:48 +01:00
|
|
|
strg = "Empty";
|
2018-06-24 02:44:47 +02:00
|
|
|
} else {
|
2018-06-23 01:39:30 +02:00
|
|
|
strg = slot.getDisplayName();
|
2015-12-22 00:04:48 +01:00
|
|
|
|
2018-06-24 02:44:47 +02:00
|
|
|
AssetUtil.renderStackToGui(slot, resolution.getScaledWidth() / 2 + 15, resolution.getScaledHeight() / 2 - 29, 1F);
|
2015-12-22 00:04:48 +01:00
|
|
|
}
|
2018-06-24 02:44:47 +02:00
|
|
|
minecraft.fontRenderer.drawStringWithShadow(TextFormatting.YELLOW + "" + TextFormatting.ITALIC + strg, resolution.getScaledWidth() / 2 + 35, resolution.getScaledHeight() / 2 - 25, StringUtil.DECIMAL_COLOR_WHITE);
|
2015-12-22 00:04:48 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-24 02:44:47 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected BlockStateContainer createBlockState() {
|
2021-02-26 22:15:48 +01:00
|
|
|
return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{COMPOST_PROP});
|
2018-06-24 02:44:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public BlockState getExtendedState(BlockState state, IBlockAccess world, BlockPos pos) {
|
2018-06-24 02:44:47 +02:00
|
|
|
TileEntity te = world.getTileEntity(pos);
|
|
|
|
if (te instanceof TileEntityCompost && state instanceof IExtendedBlockState) {
|
|
|
|
TileEntityCompost compost = (TileEntityCompost) te;
|
|
|
|
return ((IExtendedBlockState) state).withProperty(COMPOST_PROP, Pair.of(compost.getCurrentDisplay(), compost.getHeight()));
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockRenderLayer getBlockLayer() {
|
|
|
|
return BlockRenderLayer.CUTOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CompostProperty COMPOST_PROP = new CompostProperty();
|
|
|
|
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
|
|
private static class CompostProperty implements IUnlistedProperty<Pair> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "compost";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isValid(Pair value) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<Pair> getType() {
|
|
|
|
return Pair.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String valueToString(Pair value) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|