Merged stairs feature handler with block's one
Merged stairs feature handler with block's one. Relates to #9.
This commit is contained in:
parent
8c5d85d52a
commit
dc7ddfe107
|
@ -48,9 +48,6 @@ import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
|
||||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
|
||||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
@ -66,6 +63,7 @@ import appeng.helpers.ICustomCollision;
|
||||||
import appeng.util.LookDirection;
|
import appeng.util.LookDirection;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
|
||||||
|
|
||||||
public abstract class AEBaseBlock extends Block implements IAEFeature
|
public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -78,8 +76,7 @@ public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
private boolean hasSubtypes = false;
|
private boolean hasSubtypes = false;
|
||||||
private boolean isInventory = false;
|
private boolean isInventory = false;
|
||||||
private IFeatureHandler handler;
|
private IFeatureHandler handler;
|
||||||
private String textureName;
|
|
||||||
|
|
||||||
protected AxisAlignedBB boundingBox = FULL_BLOCK_AABB;
|
protected AxisAlignedBB boundingBox = FULL_BLOCK_AABB;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -131,7 +128,7 @@ public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
@Override
|
@Override
|
||||||
protected BlockStateContainer createBlockState()
|
protected BlockStateContainer createBlockState()
|
||||||
{
|
{
|
||||||
return new ExtendedBlockState( this, this.getAEStates(), new IUnlistedProperty[] {} );
|
return new BlockStateContainer( this, this.getAEStates() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IProperty[] getAEStates()
|
protected IProperty[] getAEStates()
|
||||||
|
@ -168,7 +165,7 @@ public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNormalCube(IBlockState state)
|
public boolean isNormalCube( IBlockState state )
|
||||||
{
|
{
|
||||||
return this.isFullSize() && this.isOpaque();
|
return this.isFullSize() && this.isOpaque();
|
||||||
}
|
}
|
||||||
|
@ -187,7 +184,7 @@ public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
{
|
{
|
||||||
return boundingBox;
|
return boundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCollisionBoxToList( final IBlockState state, final World w, final BlockPos pos, final AxisAlignedBB bb, final List<AxisAlignedBB> out, final Entity e )
|
public void addCollisionBoxToList( final IBlockState state, final World w, final BlockPos pos, final AxisAlignedBB bb, final List<AxisAlignedBB> out, final Entity e )
|
||||||
{
|
{
|
||||||
|
@ -211,7 +208,7 @@ public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
super.addCollisionBoxToList( state, w, pos, bb, out, e );
|
super.addCollisionBoxToList( state, w, pos, bb, out, e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SideOnly( Side.CLIENT )
|
@SideOnly( Side.CLIENT )
|
||||||
public AxisAlignedBB getSelectedBoundingBox( IBlockState state, final World w, final BlockPos pos )
|
public AxisAlignedBB getSelectedBoundingBox( IBlockState state, final World w, final BlockPos pos )
|
||||||
|
@ -297,7 +294,7 @@ public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean isOpaqueCube(IBlockState state)
|
public final boolean isOpaqueCube( IBlockState state )
|
||||||
{
|
{
|
||||||
return this.isOpaque();
|
return this.isOpaque();
|
||||||
}
|
}
|
||||||
|
@ -363,7 +360,7 @@ public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasComparatorInputOverride(IBlockState state)
|
public boolean hasComparatorInputOverride( IBlockState state )
|
||||||
{
|
{
|
||||||
return this.isInventory();
|
return this.isInventory();
|
||||||
}
|
}
|
||||||
|
@ -541,16 +538,6 @@ public abstract class AEBaseBlock extends Block implements IAEFeature
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBlockTextureName( final String texture )
|
|
||||||
{
|
|
||||||
this.textureName = texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getTextureName()
|
|
||||||
{
|
|
||||||
return this.textureName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isFullSize()
|
public boolean isFullSize()
|
||||||
{
|
{
|
||||||
return this.isFullSize;
|
return this.isFullSize;
|
||||||
|
|
|
@ -27,10 +27,10 @@ import com.google.common.base.Preconditions;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockStairs;
|
import net.minecraft.block.BlockStairs;
|
||||||
|
|
||||||
|
import appeng.core.features.AEBlockFeatureHandler;
|
||||||
import appeng.core.features.AEFeature;
|
import appeng.core.features.AEFeature;
|
||||||
import appeng.core.features.IAEFeature;
|
import appeng.core.features.IAEFeature;
|
||||||
import appeng.core.features.IFeatureHandler;
|
import appeng.core.features.IFeatureHandler;
|
||||||
import appeng.core.features.StairBlockFeatureHandler;
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class AEBaseStairBlock extends BlockStairs implements IAEFeature
|
public abstract class AEBaseStairBlock extends BlockStairs implements IAEFeature
|
||||||
|
@ -45,7 +45,7 @@ public abstract class AEBaseStairBlock extends BlockStairs implements IAEFeature
|
||||||
Preconditions.checkNotNull( block.getUnlocalizedName() );
|
Preconditions.checkNotNull( block.getUnlocalizedName() );
|
||||||
Preconditions.checkArgument( block.getUnlocalizedName().length() > 0 );
|
Preconditions.checkArgument( block.getUnlocalizedName().length() > 0 );
|
||||||
|
|
||||||
this.features = new StairBlockFeatureHandler( features, this, Optional.of( type ) );
|
this.features = new AEBlockFeatureHandler( features, this, Optional.of( type ) );
|
||||||
|
|
||||||
this.setUnlocalizedName( "stair." + type );
|
this.setUnlocalizedName( "stair." + type );
|
||||||
this.setLightOpacity( 0 );
|
this.setLightOpacity( 0 );
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.EnumSet;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||||
|
@ -35,7 +36,6 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
|
||||||
import appeng.api.definitions.IBlockDefinition;
|
import appeng.api.definitions.IBlockDefinition;
|
||||||
import appeng.block.AEBaseBlock;
|
|
||||||
import appeng.client.render.model.AEIgnoringStateMapper;
|
import appeng.client.render.model.AEIgnoringStateMapper;
|
||||||
import appeng.core.AppEng;
|
import appeng.core.AppEng;
|
||||||
import appeng.core.CreativeTab;
|
import appeng.core.CreativeTab;
|
||||||
|
@ -43,14 +43,14 @@ import appeng.core.CreativeTab;
|
||||||
|
|
||||||
public final class AEBlockFeatureHandler implements IFeatureHandler
|
public final class AEBlockFeatureHandler implements IFeatureHandler
|
||||||
{
|
{
|
||||||
private final AEBaseBlock featured;
|
private final Block featured;
|
||||||
private final FeatureNameExtractor extractor;
|
private final FeatureNameExtractor extractor;
|
||||||
private final boolean enabled;
|
private final boolean enabled;
|
||||||
private final BlockDefinition definition;
|
private final BlockDefinition definition;
|
||||||
|
|
||||||
private ResourceLocation registryName;
|
private ResourceLocation registryName;
|
||||||
|
|
||||||
public AEBlockFeatureHandler( final EnumSet<AEFeature> features, final AEBaseBlock featured, final Optional<String> subName )
|
public AEBlockFeatureHandler( final EnumSet<AEFeature> features, final Block featured, final Optional<String> subName )
|
||||||
{
|
{
|
||||||
final ActivityState state = new FeaturedActiveChecker( features ).getActivityState();
|
final ActivityState state = new FeaturedActiveChecker( features ).getActivityState();
|
||||||
|
|
||||||
|
|
|
@ -1,117 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Applied Energistics 2.
|
|
||||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package appeng.core.features;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockStairs;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
|
||||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
|
||||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
|
||||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemBlock;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.registry.IRegistry;
|
|
||||||
import net.minecraftforge.client.model.ModelLoader;
|
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
|
|
||||||
import appeng.api.definitions.IBlockDefinition;
|
|
||||||
import appeng.client.render.model.AEIgnoringStateMapper;
|
|
||||||
import appeng.core.AppEng;
|
|
||||||
import appeng.core.CreativeTab;
|
|
||||||
|
|
||||||
|
|
||||||
public class StairBlockFeatureHandler implements IFeatureHandler
|
|
||||||
{
|
|
||||||
private final BlockStairs stairs;
|
|
||||||
private final FeatureNameExtractor extractor;
|
|
||||||
private final boolean enabled;
|
|
||||||
private final BlockDefinition definition;
|
|
||||||
|
|
||||||
private ResourceLocation registryName;
|
|
||||||
|
|
||||||
public StairBlockFeatureHandler( final EnumSet<AEFeature> features, final BlockStairs stairs, final Optional<String> subName )
|
|
||||||
{
|
|
||||||
final ActivityState state = new FeaturedActiveChecker( features ).getActivityState();
|
|
||||||
|
|
||||||
this.stairs = stairs;
|
|
||||||
this.extractor = new FeatureNameExtractor( stairs.getClass(), subName );
|
|
||||||
this.enabled = state == ActivityState.Enabled;
|
|
||||||
this.definition = new BlockDefinition( stairs.getClass().getSimpleName(), stairs, state );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean isFeatureAvailable()
|
|
||||||
{
|
|
||||||
return this.enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final IBlockDefinition getDefinition()
|
|
||||||
{
|
|
||||||
return this.definition;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void register( final Side side )
|
|
||||||
{
|
|
||||||
if( this.enabled )
|
|
||||||
{
|
|
||||||
final String name = this.extractor.get();
|
|
||||||
this.stairs.setCreativeTab( CreativeTab.instance );
|
|
||||||
this.stairs.setUnlocalizedName( "appliedenergistics2." + name );
|
|
||||||
|
|
||||||
registryName = new ResourceLocation( AppEng.MOD_ID, name );
|
|
||||||
Item item;
|
|
||||||
GameRegistry.register( this.stairs.setRegistryName( registryName ) );
|
|
||||||
GameRegistry.register( item = new ItemBlock( stairs ).setRegistryName( registryName ) );
|
|
||||||
|
|
||||||
if( side == Side.CLIENT )
|
|
||||||
{
|
|
||||||
ModelBakery.registerItemVariants( item, registryName );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerModel()
|
|
||||||
{
|
|
||||||
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register( this.definition.maybeItem().get(), 0, new ModelResourceLocation( registryName, "inventory" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerStateMapper()
|
|
||||||
{
|
|
||||||
AEIgnoringStateMapper mapper = new AEIgnoringStateMapper( registryName );
|
|
||||||
ModelLoader.setCustomStateMapper( this.stairs, mapper );
|
|
||||||
( (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager() ).registerReloadListener( mapper );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerCustomModelOverride( IRegistry<ModelResourceLocation, IBakedModel> modelRegistry )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue