2017-10-04 17:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
2018-02-28 21:06:33 +01:00
|
|
|
* Copyright (C) 2016-2018 malte0811
|
2017-10-04 17:05:04 +02:00
|
|
|
* 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;
|
2017-10-04 17:05:04 +02:00
|
|
|
|
2018-05-12 19:04:38 +02:00
|
|
|
import blusunrize.immersiveengineering.ImmersiveEngineering;
|
2017-10-04 17:05:04 +02:00
|
|
|
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0;
|
|
|
|
import malte0811.industrialWires.IndustrialWires;
|
|
|
|
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
|
|
|
import malte0811.industrialWires.util.LocalSidedWorld;
|
2018-04-04 20:47:44 +02:00
|
|
|
import net.minecraft.block.Block;
|
2017-10-04 17:05:04 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2018-04-04 20:47:44 +02:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2017-10-04 17:05:04 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
2018-02-17 20:37:53 +01:00
|
|
|
import static blusunrize.immersiveengineering.common.IEContent.blockMetalDecoration0;
|
|
|
|
import static blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0.COIL_LV;
|
2018-06-15 16:15:06 +02:00
|
|
|
import static malte0811.industrialWires.mech_mb.Waveform.Phases.get;
|
2018-02-08 22:08:21 +01:00
|
|
|
import static malte0811.industrialWires.util.NBTKeys.BUFFER_IN;
|
|
|
|
import static malte0811.industrialWires.util.NBTKeys.BUFFER_OUT;
|
2018-05-14 18:51:42 +02:00
|
|
|
import static net.minecraft.util.math.BlockPos.ORIGIN;
|
2018-02-08 22:08:21 +01:00
|
|
|
|
2017-10-04 17:05:04 +02:00
|
|
|
public class MechPartSingleCoil extends MechMBPart implements IMBPartElectric {
|
2018-05-14 18:51:42 +02:00
|
|
|
{
|
|
|
|
IBlockState lightEng = getLightEngineering();
|
|
|
|
IBlockState coil = getCoil();
|
|
|
|
for (int y = -1;y<=1;y++) {
|
|
|
|
original.put(new BlockPos(-1, y, 0), lightEng);
|
|
|
|
original.put(new BlockPos(0, y, 0), coil);
|
|
|
|
original.put(new BlockPos(1, y, 0), lightEng);
|
|
|
|
}
|
|
|
|
original.put(ORIGIN, getDefaultShaft());
|
|
|
|
}
|
|
|
|
|
2018-02-08 22:08:21 +01:00
|
|
|
private double bufferToMech;
|
|
|
|
private double bufferToE;
|
2018-03-23 16:27:32 +01:00
|
|
|
|
2017-10-04 17:05:04 +02:00
|
|
|
@Override
|
2018-02-28 21:03:26 +01:00
|
|
|
public Waveform getProduced(MechEnergy state) {
|
2018-03-24 17:45:25 +01:00
|
|
|
return Waveform.forParameters(Waveform.Type.AC, get(has4Phases()), Waveform.Speed.ROTATION);
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
2018-03-23 16:27:32 +01:00
|
|
|
|
2017-10-04 17:05:04 +02:00
|
|
|
@Override
|
2018-02-08 22:08:21 +01:00
|
|
|
public double getAvailableEEnergy() {
|
|
|
|
return bufferToE;
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-08 22:08:21 +01:00
|
|
|
public void extractEEnergy(double energy) {
|
|
|
|
bufferToE -= energy;
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-28 21:03:26 +01:00
|
|
|
public double requestEEnergy(Waveform waveform, MechEnergy energy) {
|
2018-03-23 16:27:32 +01:00
|
|
|
if (has4Phases() ^ waveform.isSinglePhase()) {
|
|
|
|
return getMaxBuffer() - bufferToMech;
|
|
|
|
}
|
|
|
|
return 0;
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-28 21:03:26 +01:00
|
|
|
public void insertEEnergy(double given, Waveform waveform, MechEnergy energy) {
|
2018-02-17 20:37:53 +01:00
|
|
|
if (waveform.isDC()) {
|
2018-05-14 19:07:52 +02:00
|
|
|
bufferToMech = 0;
|
2018-02-17 20:37:53 +01:00
|
|
|
} else {
|
|
|
|
bufferToMech += given;
|
|
|
|
}
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-08 22:08:21 +01:00
|
|
|
public void createMEnergy(MechEnergy e) {
|
|
|
|
e.addEnergy(bufferToMech);
|
|
|
|
bufferToMech = 0;
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-08 22:08:21 +01:00
|
|
|
public double requestMEnergy(MechEnergy e) {
|
2018-03-23 16:27:32 +01:00
|
|
|
return getMaxBuffer() - bufferToE;
|
2018-02-08 22:08:21 +01:00
|
|
|
}
|
2017-10-04 17:05:04 +02:00
|
|
|
|
2018-02-08 22:08:21 +01:00
|
|
|
@Override
|
|
|
|
public void insertMEnergy(double added) {
|
|
|
|
bufferToE += added;
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-08 22:08:21 +01:00
|
|
|
public double getInertia() {
|
2018-03-23 16:27:32 +01:00
|
|
|
return Material.IRON.density + Material.COPPER.density;
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-03-23 16:27:32 +01:00
|
|
|
public double getMaxSpeed() {
|
2018-05-12 19:04:38 +02:00
|
|
|
return 100;
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound out) {
|
2018-02-08 22:08:21 +01:00
|
|
|
out.setDouble(BUFFER_IN, bufferToMech);
|
|
|
|
out.setDouble(BUFFER_OUT, bufferToE);
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-28 21:03:26 +01:00
|
|
|
public void readFromNBT(NBTTagCompound in) {
|
|
|
|
bufferToMech = in.getDouble(BUFFER_IN);
|
|
|
|
bufferToE = in.getDouble(BUFFER_OUT);
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getRotatingBaseModel() {
|
|
|
|
return new ResourceLocation(IndustrialWires.MODID, "block/mech_mb/single_coil.obj");
|
|
|
|
}
|
|
|
|
|
2018-03-23 16:27:32 +01:00
|
|
|
protected boolean isCoil(IBlockState state) {
|
|
|
|
return state.getBlock() == blockMetalDecoration0 &&
|
|
|
|
state.getValue(blockMetalDecoration0.property) == BlockTypes_MetalDecoration0.COIL_LV;
|
|
|
|
}
|
|
|
|
|
2018-05-14 18:51:42 +02:00
|
|
|
protected IBlockState getCoil() {
|
|
|
|
return blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property, COIL_LV);
|
2018-03-23 16:27:32 +01:00
|
|
|
}
|
|
|
|
|
2017-10-04 17:05:04 +02:00
|
|
|
@Override
|
|
|
|
public boolean canForm(LocalSidedWorld w) {
|
|
|
|
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain(0, 0, 0);
|
|
|
|
try {
|
2018-02-17 20:37:53 +01:00
|
|
|
if (!isValidDefaultCenter(w.getBlockState(pos))) {
|
2017-10-04 17:05:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pos.setPos(0, 1, 0);
|
2018-03-23 16:27:32 +01:00
|
|
|
if (!isCoil(w.getBlockState(pos))) {
|
2017-10-04 17:05:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pos.setPos(0, -1, 0);
|
2018-03-23 16:27:32 +01:00
|
|
|
if (!isCoil(w.getBlockState(pos))) {
|
2017-10-04 17:05:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-23 16:27:32 +01:00
|
|
|
for (int i = -1; i <= 1; i+=2) {
|
2017-10-04 17:05:04 +02:00
|
|
|
for (int y = -1; y <= 1; y++) {
|
2018-03-23 16:27:32 +01:00
|
|
|
pos.setPos(i, y, 0);
|
|
|
|
if (!isLightEngineering(w.getBlockState(pos))) {
|
2017-10-04 17:05:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} finally {
|
|
|
|
pos.release();//This will run after every return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-05-14 18:51:42 +02:00
|
|
|
public short getFormPattern(int offset) {
|
2017-10-04 17:05:04 +02:00
|
|
|
return 0b111_111_111;
|
|
|
|
}
|
|
|
|
|
2018-05-14 18:51:42 +02:00
|
|
|
protected static final ResourceLocation COIL_TEXTURE = new ResourceLocation(ImmersiveEngineering.MODID,
|
2018-05-12 19:04:38 +02:00
|
|
|
"blocks/metal_decoration0_coil_lv_side");
|
2018-02-17 20:37:53 +01:00
|
|
|
@Override
|
2018-05-14 18:51:42 +02:00
|
|
|
public void breakOnFailure(MechEnergy energy) {
|
|
|
|
world.setBlockState(ORIGIN, getDefaultShaft());
|
2018-03-23 16:27:32 +01:00
|
|
|
for (int i = -1; i <= 1; i+=2) {
|
|
|
|
for (int y = -1; y <= 1; y++) {
|
2018-05-14 18:51:42 +02:00
|
|
|
world.setBlockState(new BlockPos(i, y, 0), getLightEngineering());
|
2018-02-17 20:37:53 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-14 18:51:42 +02:00
|
|
|
spawnBrokenParts(8, energy, COIL_TEXTURE);
|
2018-02-17 20:37:53 +01:00
|
|
|
}
|
|
|
|
|
2017-10-04 17:05:04 +02:00
|
|
|
@Override
|
|
|
|
public MechanicalMBBlockType getType() {
|
|
|
|
return MechanicalMBBlockType.COIL_1_PHASE;
|
|
|
|
}
|
2018-03-23 16:27:32 +01:00
|
|
|
|
|
|
|
protected double getMaxBuffer() {
|
|
|
|
return 10e3;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean has4Phases() {
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-04 20:47:44 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
|
|
|
if (BlockPos.ORIGIN.equals(offsetPart)) {
|
|
|
|
return Block.FULL_BLOCK_AABB;
|
|
|
|
} else {
|
|
|
|
return new AxisAlignedBB(0, 0, .0625, 1, 1, .9375);
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 17:05:04 +02:00
|
|
|
}
|