2018-10-13 20:35:18 +02:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
2018-10-18 13:34:37 +02:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl;
|
2018-10-13 20:35:18 +02:00
|
|
|
import de.ellpeck.naturesaura.reg.IModItem;
|
|
|
|
import de.ellpeck.naturesaura.reg.IModelProvider;
|
|
|
|
import de.ellpeck.naturesaura.reg.ModRegistry;
|
2020-01-22 01:32:26 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.ModTileType;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.block.*;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2018-10-18 13:34:37 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.world.IBlockReader;
|
2018-10-13 20:35:18 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
2019-02-22 19:06:47 +01:00
|
|
|
import java.util.Random;
|
2020-01-22 01:32:26 +01:00
|
|
|
import java.util.function.Supplier;
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
public class BlockContainerImpl extends ContainerBlock implements IModItem, IModelProvider {
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
private final String baseName;
|
2020-01-22 01:32:26 +01:00
|
|
|
private final ModTileType<? extends TileEntity> tileType;
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2020-01-22 01:32:26 +01:00
|
|
|
public BlockContainerImpl(String baseName, Supplier<TileEntity> tileSupplier, Block.Properties properties) {
|
2019-11-04 19:08:49 +01:00
|
|
|
super(properties);
|
2018-10-13 20:35:18 +02:00
|
|
|
|
|
|
|
this.baseName = baseName;
|
2020-01-22 01:32:26 +01:00
|
|
|
this.tileType = new ModTileType<>(tileSupplier, this);
|
2018-10-13 20:35:18 +02:00
|
|
|
|
2018-11-29 17:58:47 +01:00
|
|
|
ModRegistry.add(this);
|
2020-01-22 01:32:26 +01:00
|
|
|
ModRegistry.add(this.tileType);
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2020-01-21 23:02:39 +01:00
|
|
|
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
2020-01-22 01:32:26 +01:00
|
|
|
return this.tileType.type.create();
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getBaseName() {
|
|
|
|
return this.baseName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockRenderType getRenderType(BlockState state) {
|
|
|
|
return BlockRenderType.MODEL;
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|
2018-10-18 13:34:37 +02:00
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
/* TODO this @Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void breakBlock(World worldIn, BlockPos pos, BlockState state) {
|
2018-10-18 13:34:37 +02:00
|
|
|
if (!worldIn.isRemote) {
|
|
|
|
TileEntity tile = worldIn.getTileEntity(pos);
|
2018-11-04 16:38:09 +01:00
|
|
|
if (tile instanceof TileEntityImpl)
|
|
|
|
((TileEntityImpl) tile).dropInventory();
|
2018-10-18 13:34:37 +02:00
|
|
|
}
|
|
|
|
super.breakBlock(worldIn, pos, state);
|
2020-01-21 21:04:44 +01:00
|
|
|
}*/
|
|
|
|
/*
|
|
|
|
TODO drop stuff
|
2018-11-04 16:38:09 +01:00
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
|
|
|
|
TileEntity tile = builder.getWorld().getTileEntity(builder.get(LootParameters.POSITION));
|
|
|
|
|
2018-11-04 16:38:09 +01:00
|
|
|
if (tile instanceof TileEntityImpl)
|
|
|
|
drops.add(((TileEntityImpl) tile).getDrop(state, fortune));
|
|
|
|
else
|
|
|
|
super.getDrops(drops, world, pos, state, fortune);
|
2020-01-21 21:04:44 +01:00
|
|
|
}*/
|
2018-11-04 16:38:09 +01:00
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
/* @Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean removedByPlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest) {
|
2018-11-04 16:38:09 +01:00
|
|
|
return willHarvest || super.removedByPlayer(state, world, pos, player, false);
|
2020-01-21 21:04:44 +01:00
|
|
|
}*/
|
2018-11-04 16:38:09 +01:00
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void harvestBlock(World worldIn, PlayerEntity player, BlockPos pos, BlockState state, @Nullable TileEntity te, ItemStack stack) {
|
2018-11-04 16:38:09 +01:00
|
|
|
super.harvestBlock(worldIn, player, pos, state, te, stack);
|
2020-01-21 21:04:44 +01:00
|
|
|
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
|
2018-11-04 16:38:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
|
2018-11-04 16:38:09 +01:00
|
|
|
TileEntity tile = worldIn.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileEntityImpl)
|
|
|
|
((TileEntityImpl) tile).loadDataOnPlace(stack);
|
|
|
|
}
|
2018-11-13 00:36:47 +01:00
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
/*@Override TODO weird redstone stuff
|
2019-10-20 22:30:49 +02:00
|
|
|
public void onBlockAdded(World worldIn, BlockPos pos, BlockState state) {
|
2018-11-13 00:36:47 +01:00
|
|
|
this.updateRedstoneState(worldIn, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
|
2018-11-13 00:36:47 +01:00
|
|
|
this.updateRedstoneState(worldIn, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateRedstoneState(World world, BlockPos pos) {
|
|
|
|
if (!world.isRemote) {
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileEntityImpl) {
|
|
|
|
TileEntityImpl impl = (TileEntityImpl) tile;
|
2019-01-27 13:57:34 +01:00
|
|
|
int newPower = world.getRedstonePowerFromNeighbors(pos);
|
2019-03-19 17:21:06 +01:00
|
|
|
if (impl.redstonePower != newPower)
|
|
|
|
world.scheduleUpdate(pos, this, this.tickRate(world));
|
2018-11-13 00:36:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 19:06:47 +01:00
|
|
|
|
2019-03-19 17:21:06 +01:00
|
|
|
@Override
|
|
|
|
public int tickRate(World worldIn) {
|
|
|
|
return 4;
|
2020-01-21 21:04:44 +01:00
|
|
|
}*/
|
2019-03-19 17:21:06 +01:00
|
|
|
|
2019-02-22 19:06:47 +01:00
|
|
|
@Override
|
2020-01-21 21:04:44 +01:00
|
|
|
public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
|
2019-02-22 19:06:47 +01:00
|
|
|
if (!worldIn.isRemote) {
|
|
|
|
TileEntity tile = worldIn.getTileEntity(pos);
|
2019-03-19 17:21:06 +01:00
|
|
|
if (tile instanceof TileEntityImpl) {
|
|
|
|
TileEntityImpl impl = (TileEntityImpl) tile;
|
|
|
|
int newPower = worldIn.getRedstonePowerFromNeighbors(pos);
|
|
|
|
if (impl.redstonePower != newPower)
|
2019-03-20 20:51:24 +01:00
|
|
|
impl.onRedstonePowerChange(newPower);
|
2019-03-19 17:21:06 +01:00
|
|
|
}
|
2019-02-22 19:06:47 +01:00
|
|
|
}
|
|
|
|
}
|
2018-10-13 20:35:18 +02:00
|
|
|
}
|