2018-03-23 16:27:32 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
|
|
|
* Copyright (C) 2016-2018 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-06-15 16:15:06 +02:00
|
|
|
package malte0811.industrialWires.mech_mb;
|
2018-03-23 16:27:32 +01:00
|
|
|
|
2018-03-24 17:45:25 +01:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
import malte0811.industrialWires.IWConfig;
|
2018-03-23 16:27:32 +01:00
|
|
|
import malte0811.industrialWires.IndustrialWires;
|
|
|
|
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
|
|
|
import malte0811.industrialWires.util.LocalSidedWorld;
|
2018-06-15 16:15:06 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2018-03-24 17:45:25 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2018-03-23 16:27:32 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2018-04-04 20:47:44 +02:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2018-03-23 16:27:32 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-03-24 17:45:25 +01:00
|
|
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
2018-06-15 16:15:06 +02:00
|
|
|
import static net.minecraft.util.EnumFacing.UP;
|
|
|
|
import static net.minecraft.util.math.BlockPos.ORIGIN;
|
2018-03-23 16:27:32 +01:00
|
|
|
|
2018-06-15 16:15:06 +02:00
|
|
|
public class MechPartCommutator extends MechPartEnergyIO {
|
|
|
|
public static ItemStack originalStack = ItemStack.EMPTY;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Waveform transform(Waveform wf, MechEnergy e) {
|
|
|
|
return wf.getCommutated(e.getSpeed(), has4Phases());
|
2018-05-14 18:51:42 +02:00
|
|
|
}
|
2018-06-15 16:15:06 +02:00
|
|
|
|
2018-03-23 16:27:32 +01:00
|
|
|
@Override
|
2018-06-15 16:15:06 +02:00
|
|
|
public double getInertia() {
|
|
|
|
return 50;
|
2018-03-23 16:27:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-15 16:15:06 +02:00
|
|
|
public double getMaxSpeed() {
|
|
|
|
return IWConfig.MechConversion.allowMBEU()?100:-1;
|
2018-03-23 16:27:32 +01:00
|
|
|
}
|
|
|
|
|
2018-06-15 16:15:06 +02:00
|
|
|
@Override
|
|
|
|
public ResourceLocation getRotatingBaseModel() {
|
|
|
|
return new ResourceLocation(IndustrialWires.MODID, "block/mech_mb/shaft_comm.obj");
|
|
|
|
}
|
2018-03-23 16:27:32 +01:00
|
|
|
|
2018-06-15 16:15:06 +02:00
|
|
|
private static final ResourceLocation KINETIC_GEN_KEY =
|
|
|
|
new ResourceLocation("ic2", "kinetic_generator");
|
2018-03-23 16:27:32 +01:00
|
|
|
@Override
|
|
|
|
public boolean canForm(LocalSidedWorld w) {
|
2018-06-15 16:15:06 +02:00
|
|
|
if (!IWConfig.MechConversion.allowMBEU()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//Center is an IC2 kinetic generator
|
|
|
|
TileEntity te = w.getTileEntity(BlockPos.ORIGIN);
|
|
|
|
if (te!=null) {
|
|
|
|
ResourceLocation loc = TileEntity.getKey(te.getClass());
|
|
|
|
return loc != null && loc.equals(KINETIC_GEN_KEY);
|
|
|
|
}
|
|
|
|
return false;
|
2018-03-23 16:27:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-05-14 18:51:42 +02:00
|
|
|
public short getFormPattern(int offset) {
|
2018-06-15 16:15:06 +02:00
|
|
|
return 0b000_010_000;
|
2018-03-23 16:27:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-15 16:15:06 +02:00
|
|
|
public void breakOnFailure(MechEnergy energy) {
|
|
|
|
//NOP
|
2018-03-23 16:27:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-15 16:15:06 +02:00
|
|
|
public ItemStack getOriginalItem(BlockPos pos) {
|
|
|
|
return pos.equals(ORIGIN)?originalStack:super.getOriginalItem(pos);
|
2018-03-23 16:27:32 +01:00
|
|
|
}
|
2018-03-24 17:45:25 +01:00
|
|
|
|
|
|
|
@Override
|
2018-06-15 16:15:06 +02:00
|
|
|
public void disassemble() {
|
|
|
|
super.disassemble();
|
|
|
|
if (IndustrialWires.ic2TeBlock!=null) {
|
|
|
|
NBTTagCompound dummyNbt = new NBTTagCompound();
|
|
|
|
dummyNbt.setString("id", KINETIC_GEN_KEY.toString());
|
|
|
|
world.setBlockState(BlockPos.ORIGIN, IndustrialWires.ic2TeBlock.getDefaultState());
|
|
|
|
world.setTileEntity(BlockPos.ORIGIN, TileEntity.create(world.getWorld(), dummyNbt));
|
|
|
|
}
|
2018-03-24 17:45:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-15 16:15:06 +02:00
|
|
|
public MechanicalMBBlockType getType() {
|
|
|
|
return MechanicalMBBlockType.SHAFT_COMMUTATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected double getMaxBuffer() {
|
|
|
|
return 2.5e3;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean has4Phases() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final ImmutableSet<Pair<BlockPos, EnumFacing>> outputs = ImmutableSet.of(
|
|
|
|
new ImmutablePair<>(ORIGIN, UP), new ImmutablePair<>(ORIGIN, null)
|
|
|
|
);
|
2018-03-24 17:45:25 +01:00
|
|
|
public Set<Pair<BlockPos, EnumFacing>> getEnergyConnections() {
|
|
|
|
return outputs;
|
|
|
|
}
|
|
|
|
|
2018-04-04 20:47:44 +02:00
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
2018-06-15 16:15:06 +02:00
|
|
|
return new AxisAlignedBB(0, .375-1/32D, 0, 1, 1, 1);
|
2018-04-04 20:47:44 +02:00
|
|
|
}
|
2018-03-23 16:27:32 +01:00
|
|
|
}
|