149 lines
5.3 KiB
Java
149 lines
5.3 KiB
Java
|
/*
|
||
|
* This file is part of Industrial Wires.
|
||
|
* Copyright (C) 2016-2017 malte0811
|
||
|
*
|
||
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* Industrial Wires 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 General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
|
|
||
|
package malte0811.industrialWires.blocks.hv;
|
||
|
|
||
|
import blusunrize.immersiveengineering.api.IEProperties;
|
||
|
import blusunrize.immersiveengineering.common.IEContent;
|
||
|
import blusunrize.immersiveengineering.common.blocks.BlockTypes_MetalsIE;
|
||
|
import blusunrize.immersiveengineering.common.blocks.metal.*;
|
||
|
import ic2.api.item.IC2Items;
|
||
|
import malte0811.industrialWires.blocks.IWProperties;
|
||
|
import malte0811.industrialWires.blocks.TileEntityIWMultiblock;
|
||
|
import net.minecraft.block.state.IBlockState;
|
||
|
import net.minecraft.entity.item.EntityItem;
|
||
|
import net.minecraft.item.ItemStack;
|
||
|
import net.minecraft.nbt.NBTTagCompound;
|
||
|
import net.minecraft.tileentity.TileEntity;
|
||
|
import net.minecraft.util.EnumFacing;
|
||
|
import net.minecraft.util.ITickable;
|
||
|
import net.minecraft.util.math.BlockPos;
|
||
|
import net.minecraft.util.math.Vec3i;
|
||
|
import net.minecraft.world.World;
|
||
|
|
||
|
import javax.annotation.Nonnull;
|
||
|
import java.util.function.BiConsumer;
|
||
|
|
||
|
public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable {
|
||
|
private static final String TYPE = "type";
|
||
|
private static final String STAGES = "stages";
|
||
|
|
||
|
public IWProperties.MarxType type = IWProperties.MarxType.NO_MODEL;
|
||
|
int stageCount = 0;
|
||
|
|
||
|
public TileEntityMarx(EnumFacing facing, IWProperties.MarxType type, boolean mirrored) {
|
||
|
this.facing = facing;
|
||
|
this.type = type;
|
||
|
this.mirrored = mirrored;
|
||
|
}
|
||
|
public TileEntityMarx() {}
|
||
|
|
||
|
@Override
|
||
|
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
|
||
|
super.writeNBT(out, updatePacket);
|
||
|
out.setInteger(TYPE, type.ordinal());
|
||
|
out.setInteger(STAGES, stageCount);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void readNBT(NBTTagCompound in, boolean updatePacket) {
|
||
|
super.readNBT(in, updatePacket);
|
||
|
type = IWProperties.MarxType.values()[in.getInteger(TYPE)];
|
||
|
stageCount = in.getInteger(STAGES);
|
||
|
}
|
||
|
|
||
|
@Nonnull
|
||
|
@Override
|
||
|
protected BlockPos getOrigin() {
|
||
|
return getPos().subtract(offset).offset(facing.getOpposite(), 3);
|
||
|
}
|
||
|
|
||
|
|
||
|
@SuppressWarnings("unchecked")
|
||
|
@Override
|
||
|
public IBlockState getOriginalBlock() {
|
||
|
int forward = dot(offset, facing.getDirectionVec());
|
||
|
int right = dot(offset, facing.rotateY().getDirectionVec())*(mirrored?-1:1);
|
||
|
int up = offset.getY();
|
||
|
if (forward==0) {
|
||
|
return IEContent.blockMetalDevice0.getDefaultState().withProperty(IEContent.blockMetalDevice0.property, BlockTypes_MetalDevice0.CAPACITOR_HV);
|
||
|
} else if (forward==-1) {
|
||
|
return IEContent.blockConnectors.getDefaultState().withProperty(IEContent.blockConnectors.property, BlockTypes_Connector.RELAY_HV)
|
||
|
.withProperty(IEProperties.FACING_ALL, facing);
|
||
|
} else if (forward==4&&up==0&&right==1) {
|
||
|
return IEContent.blockStorage.getDefaultState().withProperty(IEContent.blockStorage.property, BlockTypes_MetalsIE.STEEL);
|
||
|
} else if (forward>0) {
|
||
|
//NOP. handled by getOriginalBlockPlacer
|
||
|
} else if (forward==-2) {
|
||
|
return IEContent.blockMetalDecoration0.getDefaultState().withProperty(IEContent.blockMetalDecoration0.property, BlockTypes_MetalDecoration0.HEAVY_ENGINEERING);
|
||
|
} else if (right==0) {
|
||
|
return IEContent.blockConnectors.getDefaultState().withProperty(IEContent.blockConnectors.property, BlockTypes_Connector.CONNECTOR_REDSTONE)
|
||
|
.withProperty(IEProperties.FACING_ALL, facing);
|
||
|
} else {
|
||
|
return IEContent.blockConnectors.getDefaultState().withProperty(IEContent.blockConnectors.property, BlockTypes_Connector.CONNECTOR_HV)
|
||
|
.withProperty(IEProperties.FACING_ALL, facing);
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public BiConsumer<World, BlockPos> getOriginalBlockPlacer() {
|
||
|
IBlockState original = getOriginalBlock();
|
||
|
if (original!=null) {
|
||
|
if (original.getBlock()==IEContent.blockConnectors) {
|
||
|
return (w, p)->{
|
||
|
w.setBlockState(p, original);
|
||
|
TileEntity te = w.getTileEntity(p);
|
||
|
if (te instanceof TileEntityConnectorLV) {
|
||
|
((TileEntityConnectorLV) te).facing = original.getValue(IEProperties.FACING_ALL);
|
||
|
te.markDirty();
|
||
|
} else if (te instanceof TileEntityConnectorRedstone) {
|
||
|
((TileEntityConnectorRedstone) te).facing = original.getValue(IEProperties.FACING_ALL);
|
||
|
te.markDirty();
|
||
|
}
|
||
|
};
|
||
|
} else {
|
||
|
return (w, p)->w.setBlockState(p, original);
|
||
|
}
|
||
|
} else {
|
||
|
ItemStack hv = IC2Items.getItem("cable", "type:iron,insulation:0");
|
||
|
return (w, p)->{
|
||
|
w.setBlockToAir(p);
|
||
|
EntityItem item = new EntityItem(w, p.getX(), p.getY(), p.getZ(), hv.copy());
|
||
|
w.spawnEntity(item);
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private int dot(Vec3i a, Vec3i b) {
|
||
|
return a.getX()*b.getX()+a.getY()*b.getY()+a.getZ()*b.getZ();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void update() {
|
||
|
if (!world.isRemote&&type== IWProperties.MarxType.BOTTOM) {
|
||
|
//TODO do stuff and things
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Vec3i getSize() {
|
||
|
return new Vec3i(stageCount, 8, 2);
|
||
|
}
|
||
|
}
|