Updated subspace capacitor to 1.10 (rendering pass)

This commit is contained in:
Unknown 2018-01-22 00:50:39 +01:00
parent 03b913a823
commit f74e99c926
5 changed files with 348 additions and 29 deletions

View file

@ -4,9 +4,15 @@ import cr0s.warpdrive.Commons;
import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IWarpTool;
import cr0s.warpdrive.block.BlockAbstractContainer;
import cr0s.warpdrive.client.ClientProxy;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.BlockProperties;
import cr0s.warpdrive.data.EnumComponentType;
import cr0s.warpdrive.data.EnumDisabledInputOutput;
import cr0s.warpdrive.data.EnumTier;
import cr0s.warpdrive.event.ModelBakeEventHandler;
import cr0s.warpdrive.item.ItemComponent;
import cr0s.warpdrive.render.BakedModelEnergyBank;
import ic2.api.energy.tile.IExplosionPowerOverride;
import javax.annotation.Nonnull;
@ -15,7 +21,11 @@ import javax.annotation.Nullable;
import java.util.List;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@ -27,8 +37,13 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.IBlockAccess;
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.common.property.Properties;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
@ -39,13 +54,75 @@ import net.minecraftforge.fml.relauncher.SideOnly;
})
public class BlockEnergyBank extends BlockAbstractContainer implements IExplosionPowerOverride {
public static final IProperty<EnumDisabledInputOutput> CONFIG = PropertyEnum.create("config" , EnumDisabledInputOutput.class);
public static final IUnlistedProperty<EnumDisabledInputOutput> DOWN = Properties.toUnlisted(PropertyEnum.create("down" , EnumDisabledInputOutput.class));
public static final IUnlistedProperty<EnumDisabledInputOutput> UP = Properties.toUnlisted(PropertyEnum.create("up" , EnumDisabledInputOutput.class));
public static final IUnlistedProperty<EnumDisabledInputOutput> NORTH = Properties.toUnlisted(PropertyEnum.create("north", EnumDisabledInputOutput.class));
public static final IUnlistedProperty<EnumDisabledInputOutput> SOUTH = Properties.toUnlisted(PropertyEnum.create("south", EnumDisabledInputOutput.class));
public static final IUnlistedProperty<EnumDisabledInputOutput> WEST = Properties.toUnlisted(PropertyEnum.create("west" , EnumDisabledInputOutput.class));
public static final IUnlistedProperty<EnumDisabledInputOutput> EAST = Properties.toUnlisted(PropertyEnum.create("east" , EnumDisabledInputOutput.class));
public BlockEnergyBank(final String registryName) {
super(registryName, Material.IRON);
setUnlocalizedName("warpdrive.energy.EnergyBank.");
hasSubBlocks = true;
setDefaultState(getDefaultState()
.withProperty(BlockProperties.TIER, EnumTier.BASIC)
.withProperty(CONFIG, EnumDisabledInputOutput.DISABLED)
);
GameRegistry.registerTileEntity(TileEntityEnergyBank.class, WarpDrive.PREFIX + registryName);
}
@Nonnull
@Override
protected BlockStateContainer createBlockState() {
return new ExtendedBlockState(this,
new IProperty[] { BlockProperties.TIER, CONFIG },
new IUnlistedProperty[] { DOWN, UP, NORTH, SOUTH, WEST, EAST });
}
@SuppressWarnings("deprecation")
@Nonnull
@Override
public IBlockState getStateFromMeta(int metadata) {
return getDefaultState()
.withProperty(BlockProperties.TIER, EnumTier.get(metadata % 4));
}
@Override
public int getMetaFromState(IBlockState blockState) {
return blockState.getValue(BlockProperties.TIER).getIndex();
}
@Nonnull
@Override
public IBlockState getExtendedState(@Nonnull IBlockState blockState, IBlockAccess blockAccess, BlockPos blockPos) {
if (!(blockState instanceof IExtendedBlockState)) {
return blockState;
}
final TileEntity tileEntity = blockAccess.getTileEntity(blockPos);
if (!(tileEntity instanceof TileEntityEnergyBank)) {
return blockState;
}
final TileEntityEnergyBank tileEntityEnergyBank = (TileEntityEnergyBank) tileEntity;
return ((IExtendedBlockState) blockState)
.withProperty(DOWN, tileEntityEnergyBank.getMode(EnumFacing.DOWN))
.withProperty(UP, tileEntityEnergyBank.getMode(EnumFacing.UP))
.withProperty(NORTH, tileEntityEnergyBank.getMode(EnumFacing.NORTH))
.withProperty(SOUTH, tileEntityEnergyBank.getMode(EnumFacing.SOUTH))
.withProperty(WEST, tileEntityEnergyBank.getMode(EnumFacing.WEST))
.withProperty(EAST, tileEntityEnergyBank.getMode(EnumFacing.EAST));
}
@SuppressWarnings("deprecation")
@Nonnull
@Override
public IBlockState getActualState(@Nonnull final IBlockState blockState, final IBlockAccess blockAccess, final BlockPos pos) {
return super.getActualState(blockState, blockAccess, pos);
}
@Nonnull
@Override
public TileEntity createNewTileEntity(@Nonnull World world, int metadata) {
@ -65,24 +142,44 @@ public class BlockEnergyBank extends BlockAbstractContainer implements IExplosio
list.add(itemStack);
if (tier > 0) {
itemStack = new ItemStack(item, 1, tier);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
nbtTagCompound.setByte("tier", tier);
nbtTagCompound.setInteger("energy", WarpDriveConfig.ENERGY_BANK_MAX_ENERGY_STORED[tier - 1]);
itemStack.setTagCompound(nbtTagCompound);
final NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("tier", tier);
tagCompound.setInteger("energy", WarpDriveConfig.ENERGY_BANK_MAX_ENERGY_STORED[tier - 1]);
itemStack.setTagCompound(tagCompound);
list.add(itemStack);
}
}
}
@SideOnly(Side.CLIENT)
@Override
public void modelInitialisation() {
final Item item = Item.getItemFromBlock(this);
ClientProxy.modelInitialisation(item);
// Bind our TESR to our tile entity
// ClientRegistry.bindTileEntitySpecialRenderer(TileEntityForceFieldProjector.class, new TileEntityForceFieldProjectorRenderer());
// register (smart) baked model
for (final EnumDisabledInputOutput enumDisabledInputOutput : CONFIG.getAllowedValues()) {
for (final EnumTier enumTier : BlockProperties.TIER.getAllowedValues()) {
final String variant = String.format("%s=%s,%s=%s",
CONFIG.getName(), enumDisabledInputOutput,
BlockProperties.TIER.getName(), enumTier);
ModelBakeEventHandler.registerBakedModel(new ModelResourceLocation(getRegistryName(), variant), BakedModelEnergyBank.class);
}
}
}
@SideOnly(Side.CLIENT)
@Override
public byte getTier(final ItemStack itemStack) {
if (itemStack == null || itemStack.getItem() != Item.getItemFromBlock(this)) {
return 1;
}
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
if (nbtTagCompound != null && nbtTagCompound.hasKey("tier")) {
return nbtTagCompound.getByte("tier");
final NBTTagCompound tagCompound = itemStack.getTagCompound();
if (tagCompound != null && tagCompound.hasKey("tier")) {
return tagCompound.getByte("tier");
} else {
return (byte) itemStack.getItemDamage();
}
@ -99,38 +196,37 @@ public class BlockEnergyBank extends BlockAbstractContainer implements IExplosio
return defaultPower;
}
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer entityPlayer, EnumHand hand, @Nullable ItemStack itemStackHeld, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return false;
}
TileEntity tileEntity = world.getTileEntity(blockPos);
final TileEntity tileEntity = world.getTileEntity(blockPos);
if (!(tileEntity instanceof TileEntityEnergyBank)) {
return false;
}
TileEntityEnergyBank tileEntityEnergyBank = (TileEntityEnergyBank) tileEntity;
final TileEntityEnergyBank tileEntityEnergyBank = (TileEntityEnergyBank) tileEntity;
if (itemStackHeld != null && itemStackHeld.getItem() instanceof IWarpTool) {
if (entityPlayer.isSneaking()) {
tileEntityEnergyBank.setMode(facing, (byte)((tileEntityEnergyBank.getMode(facing) + 2) % 3));
tileEntityEnergyBank.setMode(facing, tileEntityEnergyBank.getMode(facing).getPrevious());
} else {
tileEntityEnergyBank.setMode(facing, (byte)((tileEntityEnergyBank.getMode(facing) + 1) % 3));
tileEntityEnergyBank.setMode(facing, tileEntityEnergyBank.getMode(facing).getNext());
}
ItemStack itemStack = new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(blockState));
final ItemStack itemStack = new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(blockState));
switch (tileEntityEnergyBank.getMode(facing)) {
case TileEntityEnergyBank.MODE_INPUT:
case INPUT:
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.guide.prefix")
.appendSibling(new TextComponentTranslation(itemStack.getUnlocalizedName() + ".name"))
.appendSibling(new TextComponentTranslation("warpdrive.energy.side.changedToInput", facing.name())) );
return true;
case TileEntityEnergyBank.MODE_OUTPUT:
case OUTPUT:
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.guide.prefix")
.appendSibling(new TextComponentTranslation(itemStack.getUnlocalizedName() + ".name"))
.appendSibling(new TextComponentTranslation("warpdrive.energy.side.changedToOutput", facing.name())) );
return true;
case TileEntityEnergyBank.MODE_DISABLED:
case DISABLED:
default:
Commons.addChatMessage(entityPlayer, new TextComponentTranslation("warpdrive.guide.prefix")
.appendSibling(new TextComponentTranslation(itemStack.getUnlocalizedName() + ".name"))

View file

@ -4,6 +4,7 @@ import cr0s.warpdrive.Commons;
import cr0s.warpdrive.block.TileEntityAbstractEnergy;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.EnumComponentType;
import cr0s.warpdrive.data.EnumDisabledInputOutput;
import javax.annotation.Nonnull;
@ -16,14 +17,17 @@ import net.minecraft.util.text.TextComponentString;
public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
static final byte MODE_DISABLED = 0;
static final byte MODE_INPUT = 1;
static final byte MODE_OUTPUT = 2;
private static final byte[] MODE_DEFAULT_SIDES = { MODE_INPUT, MODE_INPUT, MODE_OUTPUT, MODE_OUTPUT, MODE_OUTPUT, MODE_OUTPUT };
private static final EnumDisabledInputOutput[] MODE_DEFAULT_SIDES = {
EnumDisabledInputOutput.INPUT,
EnumDisabledInputOutput.INPUT,
EnumDisabledInputOutput.OUTPUT,
EnumDisabledInputOutput.OUTPUT,
EnumDisabledInputOutput.OUTPUT,
EnumDisabledInputOutput.OUTPUT };
// persistent properties
private byte tier = -1;
private byte[] modeSide = MODE_DEFAULT_SIDES.clone();
private EnumDisabledInputOutput[] modeSide = MODE_DEFAULT_SIDES.clone();
public TileEntityEnergyBank() {
this((byte) 1);
@ -106,24 +110,24 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
@Override
public boolean energy_canInput(EnumFacing from) {
return modeSide[from.ordinal()] == MODE_INPUT;
return modeSide[from.ordinal()] == EnumDisabledInputOutput.INPUT;
}
@Override
public boolean energy_canOutput(EnumFacing to) {
return modeSide[to.ordinal()] == MODE_OUTPUT;
return modeSide[to.ordinal()] == EnumDisabledInputOutput.OUTPUT;
}
byte getTier() {
return tier;
}
byte getMode(final EnumFacing facing) {
EnumDisabledInputOutput getMode(final EnumFacing facing) {
return modeSide[facing.ordinal()];
}
void setMode(final EnumFacing facing, final byte mode) {
modeSide[facing.ordinal()] = (byte)(mode % 3);
void setMode(final EnumFacing facing, final EnumDisabledInputOutput enumDisabledInputOutput) {
modeSide[facing.ordinal()] = enumDisabledInputOutput;
markDirty();
energy_resetConnections(facing);
}
@ -135,10 +139,15 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
}
// Forge overrides
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbtTagCompound) {
super.writeToNBT(nbtTagCompound);
nbtTagCompound.setByte("tier", tier);
nbtTagCompound.setByteArray("modeSide", modeSide);
final byte[] bytes = new byte[EnumFacing.values().length];
for (final EnumFacing enumFacing : EnumFacing.values()) {
bytes[enumFacing.ordinal()] = (byte) modeSide[enumFacing.ordinal()].getIndex();
}
nbtTagCompound.setByteArray("modeSide", bytes);
return nbtTagCompound;
}
@ -146,9 +155,13 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
public void readFromNBT(NBTTagCompound nbtTagCompound) {
super.readFromNBT(nbtTagCompound);
tier = nbtTagCompound.getByte("tier");
modeSide = nbtTagCompound.getByteArray("modeSide");
if (modeSide.length != 6) {
final byte[] bytes = nbtTagCompound.getByteArray("modeSide");
if (bytes.length != 6) {
modeSide = MODE_DEFAULT_SIDES.clone();
} else {
for (final EnumFacing enumFacing : EnumFacing.values()) {
modeSide[enumFacing.ordinal()] = EnumDisabledInputOutput.get(bytes[enumFacing.ordinal()]);
}
}
}

View file

@ -0,0 +1,53 @@
package cr0s.warpdrive.data;
import javax.annotation.Nonnull;
import java.util.HashMap;
import net.minecraft.util.IStringSerializable;
public enum EnumDisabledInputOutput implements IStringSerializable {
DISABLED ("disabled", 0),
INPUT ("input" , 1),
OUTPUT ("output" , 2);
private final String name;
private final int index;
// cached values
public static final int length;
private static final HashMap<Integer, EnumDisabledInputOutput> ID_MAP = new HashMap<>();
static {
length = EnumDisabledInputOutput.values().length;
for (EnumDisabledInputOutput enumDisabledInputOutput : values()) {
ID_MAP.put(enumDisabledInputOutput.index, enumDisabledInputOutput);
}
}
EnumDisabledInputOutput(final String name, final int index) {
this.name = name;
this.index = index;
}
@Nonnull
@Override
public String getName() {
return name;
}
public int getIndex() {
return index;
}
public EnumDisabledInputOutput getNext() {
return get((index + 1) % 3);
}
public EnumDisabledInputOutput getPrevious() {
return get((index + 2) % 3);
}
public static EnumDisabledInputOutput get(final int index) {
return ID_MAP.get(index);
}
}

View file

@ -0,0 +1,139 @@
package cr0s.warpdrive.render;
import cr0s.warpdrive.api.IMyBakedModel;
import cr0s.warpdrive.block.energy.BlockEnergyBank;
import cr0s.warpdrive.data.EnumDisabledInputOutput;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.property.IExtendedBlockState;
public class BakedModelEnergyBank implements IBakedModel, IMyBakedModel {
private ResourceLocation resourceLocation;
private IBakedModel bakedModelOriginal;
public BakedModelEnergyBank() {
}
@Override
public void setResourceLocation(final ResourceLocation resourceLocation) {
this.resourceLocation = resourceLocation;
}
@Override
public void setOriginalBakedModel(final IBakedModel bakedModel) {
this.bakedModelOriginal = bakedModel;
}
public IBakedModel getOriginalBakedModel() {
return bakedModelOriginal;
}
@Nonnull
@Override
public List<BakedQuad> getQuads(@Nullable final IBlockState blockState, @Nullable final EnumFacing facing, final long rand) {
assert(resourceLocation != null);
assert(bakedModelOriginal != null);
if (blockState instanceof IExtendedBlockState) {
final IExtendedBlockState extendedBlockState = (IExtendedBlockState) blockState;
final EnumDisabledInputOutput enumDisabledInputOutput = getEnumDisabledInputOutput(extendedBlockState, facing);
final IBlockState blockStateToRender = extendedBlockState.getClean().withProperty(BlockEnergyBank.CONFIG, enumDisabledInputOutput);
// remap to the json model representing the proper state
final BlockModelShapes blockModelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
final IBakedModel bakedModelWrapped = blockModelShapes.getModelForState(blockStateToRender);
final IBakedModel bakedModelToRender = ((BakedModelEnergyBank) bakedModelWrapped).getOriginalBakedModel();
return bakedModelToRender.getQuads(blockStateToRender, facing, rand);
}
return getDefaultQuads(facing, rand);
}
public EnumDisabledInputOutput getEnumDisabledInputOutput(final IExtendedBlockState extendedBlockState, @Nullable final EnumFacing facing) {
if (facing == null) {
return EnumDisabledInputOutput.DISABLED;
}
switch (facing) {
case DOWN : return extendedBlockState.getValue(BlockEnergyBank.DOWN);
case UP : return extendedBlockState.getValue(BlockEnergyBank.UP);
case NORTH: return extendedBlockState.getValue(BlockEnergyBank.NORTH);
case SOUTH: return extendedBlockState.getValue(BlockEnergyBank.SOUTH);
case WEST : return extendedBlockState.getValue(BlockEnergyBank.WEST);
case EAST : return extendedBlockState.getValue(BlockEnergyBank.EAST);
default: return EnumDisabledInputOutput.DISABLED;
}
}
public List<BakedQuad> getDefaultQuads(final EnumFacing side, final long rand) {
final IBlockState blockState = Blocks.FIRE.getDefaultState();
return Minecraft.getMinecraft().getBlockRendererDispatcher()
.getModelForState(blockState).getQuads(blockState, side, rand);
}
@Override
public boolean isAmbientOcclusion() {
return bakedModelOriginal.isAmbientOcclusion();
}
@Override
public boolean isGui3d() {
return bakedModelOriginal.isGui3d();
}
@Override
public boolean isBuiltInRenderer() {
return bakedModelOriginal.isBuiltInRenderer();
}
@Nonnull
@Override
public TextureAtlasSprite getParticleTexture() {
// Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("warpdrive:someTexture")
return bakedModelOriginal.getParticleTexture();
}
@Nonnull
@Override
public ItemCameraTransforms getItemCameraTransforms() {
// ItemCameraTransforms.DEFAULT
return bakedModelOriginal.getItemCameraTransforms();
}
@Nonnull
@Override
public ItemOverrideList getOverrides() {
// return itemOverrideList
return bakedModelOriginal.getOverrides();
}
/*
private final ItemOverrideList itemOverrideList = new ItemOverrideList(ImmutableList.of()) {
@Nonnull
@Override
public IBakedModel handleItemState(@Nonnull IBakedModel model, @Nonnull ItemStack stack, @Nonnull World world, @Nonnull EntityLivingBase entity) {
if (!stack.hasTagCompound()) {
return Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(Blocks.FIRE.getDefaultState());
}
final IBlockState state = NBTUtil.func_190008_d(stack.getTagCompound().getCompoundTag("BLOCKSTATE"));
return Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(state);
}
};
/**/
}

View file

@ -0,0 +1,18 @@
{
"forge_marker": 1,
"variants": {
"inventory": [{}],
"config=disabled,tier=creative": { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_creative-disabled" } },
"config=input,tier=creative" : { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_creative-input" } },
"config=output,tier=creative" : { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_creative-output" } },
"config=disabled,tier=basic" : { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_basic-disabled" } },
"config=input,tier=basic" : { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_basic-input" } },
"config=output,tier=basic" : { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_basic-output" } },
"config=disabled,tier=advanced": { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_advanced-disabled" } },
"config=input,tier=advanced" : { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_advanced-input" } },
"config=output,tier=advanced" : { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_advanced-output" } },
"config=disabled,tier=superior": { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_superior-disabled" } },
"config=input,tier=superior" : { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_superior-input" } },
"config=output,tier=superior" : { "model": "minecraft:cube_all", "textures": { "all" : "warpdrive:blocks/energy/energy_bank_superior-output" } }
}
}