mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 00:38:35 +01:00
remove greenhouse glass tile entity
I am not sure if this is faster or slower than the old tile entity, but it certainly is more performant. Numbers may be adjusted to try and fix what the old speed was (every 50 ticks)
This commit is contained in:
parent
4493a687ce
commit
beef72d35d
3 changed files with 66 additions and 131 deletions
|
@ -10,15 +10,18 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.blocks;
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
import java.util.Random;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityGreenhouseGlass;
|
|
||||||
|
import org.apache.commons.lang3.tuple.Triple;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.IGrowable;
|
||||||
import net.minecraft.block.SoundType;
|
import net.minecraft.block.SoundType;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.item.EnumRarity;
|
import net.minecraft.item.EnumRarity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.BlockRenderLayer;
|
import net.minecraft.util.BlockRenderLayer;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
@ -27,50 +30,73 @@ import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
public class BlockGreenhouseGlass extends BlockContainerBase{
|
public class BlockGreenhouseGlass extends BlockBase {
|
||||||
|
|
||||||
public BlockGreenhouseGlass(String name){
|
public BlockGreenhouseGlass(String name) {
|
||||||
super(Material.ROCK, name);
|
super(Material.GLASS, name);
|
||||||
this.setHarvestLevel("pickaxe", 0);
|
this.setHarvestLevel("pickaxe", 0);
|
||||||
this.setHardness(0.5F);
|
this.setHardness(0.5F);
|
||||||
this.setResistance(10.0F);
|
this.setResistance(10.0F);
|
||||||
this.setSoundType(SoundType.STONE);
|
this.setSoundType(SoundType.GLASS);
|
||||||
}
|
this.setTickRandomly(true);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFullCube(IBlockState state){
|
public boolean isFullCube(IBlockState state) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public boolean isOpaqueCube(IBlockState state) {
|
||||||
@SideOnly(Side.CLIENT)
|
return false;
|
||||||
public boolean shouldSideBeRendered(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side){
|
}
|
||||||
IBlockState otherState = world.getBlockState(pos.offset(side));
|
|
||||||
Block block = otherState.getBlock();
|
|
||||||
|
|
||||||
return state != otherState || block != this && super.shouldSideBeRendered(state, world, pos, side);
|
@Override
|
||||||
|
@Deprecated
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public boolean shouldSideBeRendered(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
|
||||||
|
IBlockState otherState = world.getBlockState(pos.offset(side));
|
||||||
|
Block block = otherState.getBlock();
|
||||||
|
|
||||||
}
|
return state != otherState || block != this && super.shouldSideBeRendered(state, world, pos, side);
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public boolean isOpaqueCube(IBlockState state){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public BlockRenderLayer getBlockLayer(){
|
public BlockRenderLayer getBlockLayer() {
|
||||||
return BlockRenderLayer.CUTOUT;
|
return BlockRenderLayer.CUTOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumRarity getRarity(ItemStack stack){
|
public EnumRarity getRarity(ItemStack stack) {
|
||||||
return EnumRarity.EPIC;
|
return EnumRarity.EPIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int par2){
|
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||||
return new TileEntityGreenhouseGlass();
|
if (world.isRemote) return;
|
||||||
}
|
|
||||||
|
if (rand.nextInt(2) == 0 && world.canBlockSeeSky(pos) && world.isDaytime()) {
|
||||||
|
|
||||||
|
Triple<BlockPos, IBlockState, IGrowable> trip = firstSolidBlock(world, pos);
|
||||||
|
|
||||||
|
if (trip != null && trip.getRight().canGrow(world, trip.getLeft(), trip.getMiddle(), false)) {
|
||||||
|
trip.getRight().grow(world, rand, trip.getLeft(), trip.getMiddle());
|
||||||
|
world.playEvent(2005, trip.getMiddle().isOpaqueCube() ? trip.getLeft().up() : trip.getLeft(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Triple<BlockPos, IBlockState, IGrowable> firstSolidBlock(World world, BlockPos glassPos) {
|
||||||
|
BlockPos.MutableBlockPos mut = new BlockPos.MutableBlockPos(glassPos);
|
||||||
|
while (true) {
|
||||||
|
mut.setPos(mut.getX(), mut.getY() - 1, mut.getZ());
|
||||||
|
IBlockState state = world.getBlockState(mut);
|
||||||
|
if (!state.getBlock().isAir(state, world, mut)) {
|
||||||
|
if (state.getBlock() instanceof IGrowable) return Triple.of(mut.toImmutable(), state, (IGrowable) state.getBlock());
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,6 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
register(TileEntityFurnaceSolar.class);
|
register(TileEntityFurnaceSolar.class);
|
||||||
register(TileEntityHeatCollector.class);
|
register(TileEntityHeatCollector.class);
|
||||||
register(TileEntityItemRepairer.class);
|
register(TileEntityItemRepairer.class);
|
||||||
register(TileEntityGreenhouseGlass.class);
|
|
||||||
register(TileEntityBreaker.class);
|
register(TileEntityBreaker.class);
|
||||||
register(TileEntityDropper.class);
|
register(TileEntityDropper.class);
|
||||||
register(TileEntityInputterAdvanced.class);
|
register(TileEntityInputterAdvanced.class);
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
/*
|
|
||||||
* This file ("TileEntityGreenhouseGlass.java") is part of the Actually Additions mod for Minecraft.
|
|
||||||
* It is created and owned by Ellpeck and distributed
|
|
||||||
* under the Actually Additions License to be found at
|
|
||||||
* http://ellpeck.de/actaddlicense
|
|
||||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
||||||
*
|
|
||||||
* © 2015-2017 Ellpeck
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockGrass;
|
|
||||||
import net.minecraft.block.IGrowable;
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraftforge.common.IPlantable;
|
|
||||||
|
|
||||||
public class TileEntityGreenhouseGlass extends TileEntityBase{
|
|
||||||
|
|
||||||
private int timeUntilNextFert;
|
|
||||||
|
|
||||||
public TileEntityGreenhouseGlass(){
|
|
||||||
super("greenhouseGlass");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
||||||
super.writeSyncableNBT(compound, type);
|
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
|
||||||
this.timeUntilNextFert = compound.getInteger("Time");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
||||||
super.readSyncableNBT(compound, type);
|
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
|
||||||
compound.setInteger("Time", this.timeUntilNextFert);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity(){
|
|
||||||
super.updateEntity();
|
|
||||||
if(!this.world.isRemote){
|
|
||||||
if(this.world.canBlockSeeSky(this.getPos()) && this.world.isDaytime()){
|
|
||||||
if(this.timeUntilNextFert > 0){
|
|
||||||
this.timeUntilNextFert--;
|
|
||||||
if(this.timeUntilNextFert <= 0){
|
|
||||||
BlockPos blockToFert = this.blockToFertilize();
|
|
||||||
if(blockToFert != null){
|
|
||||||
IBlockState state = this.world.getBlockState(blockToFert);
|
|
||||||
Block block = state.getBlock();
|
|
||||||
int metaBefore = block.getMetaFromState(state);
|
|
||||||
block.updateTick(this.world, blockToFert, this.world.getBlockState(blockToFert), this.world.rand);
|
|
||||||
|
|
||||||
IBlockState newState = this.world.getBlockState(blockToFert);
|
|
||||||
if(newState.getBlock().getMetaFromState(newState) != metaBefore){
|
|
||||||
this.world.playEvent(2005, blockToFert, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
int time = 50;
|
|
||||||
this.timeUntilNextFert = time+this.world.rand.nextInt(time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockPos blockToFertilize(){
|
|
||||||
for(int i = this.pos.getY()-1; i > 0; i--){
|
|
||||||
BlockPos offset = new BlockPos(this.pos.getX(), i, this.pos.getZ());
|
|
||||||
Block block = this.world.getBlockState(offset).getBlock();
|
|
||||||
if(block != null && !this.world.isAirBlock(offset)){
|
|
||||||
if((block instanceof IGrowable || block instanceof IPlantable) && !(block instanceof BlockGrass)){
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue