Pick block works on mechanical multiblocks now
Fix crashes without IC2
This commit is contained in:
parent
b43150d6c9
commit
a756de6ace
|
@ -76,7 +76,7 @@ dependencies {
|
|||
compileOnly "RebornCore:RebornCore-1.12:3.2.+:dev"
|
||||
compileOnly 'com.elytradev:mirage:2.0.1-SNAPSHOT'
|
||||
compileOnly "mezz.jei:jei_1.12:4.+"
|
||||
compileOnly "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.+"
|
||||
compileOnly "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.8.460"
|
||||
}
|
||||
|
||||
jar {
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
package malte0811.industrialWires.blocks;
|
||||
|
||||
import malte0811.industrialWires.util.MiscUtils;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -72,7 +71,7 @@ public abstract class BlockIWMultiblock extends BlockIWBase {
|
|||
public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) {
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (te instanceof TileEntityIWMultiblock) {
|
||||
return MiscUtils.getItemStack(((TileEntityIWMultiblock) te).getOriginalBlock(), world, pos);
|
||||
return ((TileEntityIWMultiblock) te).getOriginalItem();
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,10 @@ public abstract class TileEntityIWMultiblock extends TileEntityIWBase implements
|
|||
@Nonnull
|
||||
protected abstract BlockPos getOrigin();
|
||||
public abstract IBlockState getOriginalBlock();
|
||||
public ItemStack getOriginalItem() {
|
||||
IBlockState state = getOriginalBlock();
|
||||
return new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state));
|
||||
}
|
||||
public BiConsumer<World, BlockPos> getOriginalBlockPlacer() {
|
||||
return (w, p)->w.setBlockState(p, getOriginalBlock());
|
||||
}
|
||||
|
@ -93,7 +97,7 @@ public abstract class TileEntityIWMultiblock extends TileEntityIWBase implements
|
|||
if (!pos.equals(this.pos)) {
|
||||
part.getOriginalBlockPlacer().accept(world, pos);
|
||||
} else if (part.getOriginalBlock()!=null) {
|
||||
ItemStack drop = MiscUtils.getItemStack(part.getOriginalBlock(), world, pos);
|
||||
ItemStack drop = getOriginalItem();
|
||||
world.spawnEntity(new EntityItem(world, pos.getX()+.5,pos.getY()+.5,pos.getZ()+.5, drop));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,8 @@ package malte0811.industrialWires.blocks.converter;
|
|||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IRedstoneOutput;
|
||||
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0;
|
||||
import blusunrize.immersiveengineering.common.util.Utils;
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergyEmitter;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
@ -29,9 +28,11 @@ import malte0811.industrialWires.IndustrialWires;
|
|||
import malte0811.industrialWires.blocks.IBlockBoundsIW.IBlockBoundsDirectional;
|
||||
import malte0811.industrialWires.blocks.ISyncReceiver;
|
||||
import malte0811.industrialWires.blocks.TileEntityIWMultiblock;
|
||||
import malte0811.industrialWires.compat.Compat;
|
||||
import malte0811.industrialWires.converter.*;
|
||||
import malte0811.industrialWires.network.MessageTileSyncIW;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -44,7 +45,6 @@ import net.minecraft.util.*;
|
|||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
|
@ -106,10 +106,7 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
}
|
||||
}
|
||||
if (firstTick) {
|
||||
//TODO make safe for when IC2 isn't installed
|
||||
if (!world.isRemote && IndustrialWires.hasIC2) {
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
}
|
||||
Compat.loadIC2Tile.accept(this);
|
||||
firstTick = false;
|
||||
}
|
||||
if (world.isRemote) {
|
||||
|
@ -347,7 +344,21 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
|
||||
@Override
|
||||
public IBlockState getOriginalBlock() {
|
||||
return Blocks.AIR.getDefaultState();// TODO implement for pick block
|
||||
return Blocks.AIR.getDefaultState();//Irrelevant, the method below is used for pick block
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOriginalItem() {
|
||||
Vec3i offsetDirectional = getOffsetDir();
|
||||
TileEntityMechMB master = masterOr(this, this);
|
||||
int id = getPart(offsetDirectional.getZ(), master);
|
||||
if (id < 0) {
|
||||
return new ItemStack(blockMetalDecoration0, 1,
|
||||
BlockTypes_MetalDecoration0.HEAVY_ENGINEERING.ordinal());
|
||||
}
|
||||
MechMBPart part = master.mechanical[id];
|
||||
BlockPos offsetPart = new BlockPos(offsetDirectional.getX(), offsetDirectional.getY(), offsetDirectional.getZ() - master.offsets[id]);
|
||||
return part.getOriginalItem(offsetPart);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -417,6 +428,17 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
}
|
||||
}
|
||||
master.disassemble(failed);
|
||||
try {
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
NonNullList<ItemStack> drops = NonNullList.create();
|
||||
state.getBlock().getDrops(drops, world, pos, state, 0);
|
||||
world.setBlockToAir(pos);
|
||||
for (ItemStack s:drops) {
|
||||
Block.spawnAsEntity(world, pos, s);
|
||||
}
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -430,18 +452,22 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
world.setBlockState(pos.down(),
|
||||
blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property, HEAVY_ENGINEERING));
|
||||
for (MechMBPart mech : mechanical) {
|
||||
mech.disassemble(failed.contains(mech), energyState);
|
||||
short pattern = mech.getFormPattern();
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (((pattern >> i) & 1) != 0) {
|
||||
BlockPos pos = new BlockPos(i % 3 - 1, i / 3 - 1, 0);
|
||||
if (mech.world.getBlockState(pos).getBlock() == IndustrialWires.mechanicalMB) {
|
||||
mech.world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (failed.contains(mech)) {
|
||||
world.playSound(null, mech.world.getOrigin(), new SoundEvent(mmbBang), SoundCategory.BLOCKS, 1, 1);
|
||||
mech.breakOnFailure(energyState);
|
||||
} else {
|
||||
mech.disassemble();
|
||||
}
|
||||
for (int l = 0;l<mech.getLength();l++) {
|
||||
short pattern = mech.getFormPattern(l);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (((pattern >> i) & 1) != 0) {
|
||||
BlockPos pos = new BlockPos(i % 3 - 1, i / 3 - 1, -l);
|
||||
if (mech.world.getBlockState(pos).getBlock() == IndustrialWires.mechanicalMB) {
|
||||
mech.world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockPos otherEnd = offset(pos, facing.getOpposite(), mirrored, 0,
|
||||
|
@ -531,7 +557,7 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
@Override
|
||||
public void invalidate() {
|
||||
if (!world.isRemote && !firstTick)
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
Compat.unloadIC2Tile.accept(this);
|
||||
firstTick = true;
|
||||
super.invalidate();
|
||||
}
|
||||
|
@ -540,7 +566,7 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
public void onChunkUnload() {
|
||||
super.onChunkUnload();
|
||||
if (!world.isRemote && !firstTick)
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
Compat.unloadIC2Tile.accept(this);
|
||||
firstTick = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,53 +17,91 @@ package malte0811.industrialWires.compat;
|
|||
|
||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.api.tool.ToolboxHandler;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import crafttweaker.CraftTweakerAPI;
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import ic2.api.item.IBoxable;
|
||||
import ic2.api.item.IC2Items;
|
||||
import malte0811.industrialWires.converter.MechPartCommutator;
|
||||
import malte0811.industrialWires.hv.MarxOreHandler;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Compat {
|
||||
public static Consumer<MarxOreHandler.OreInfo> addMarx = (o)->{};
|
||||
public static Consumer<MarxOreHandler.OreInfo> removeMarx = (o)->{};
|
||||
static Consumer<MarxOreHandler.OreInfo> addMarx = (o) -> {
|
||||
};
|
||||
static Consumer<MarxOreHandler.OreInfo> removeMarx = (o) -> {
|
||||
};
|
||||
public static Consumer<TileEntity> loadIC2Tile = te -> {
|
||||
};
|
||||
public static Consumer<TileEntity> unloadIC2Tile = te -> {
|
||||
};
|
||||
private static Map<String, Class<? extends CompatModule>> modules = ImmutableMap.of("ic2", CompatIC2.class,
|
||||
"crafttweaker", CompatCT.class);
|
||||
|
||||
private static Method preInit;
|
||||
private static Method init;
|
||||
|
||||
static {
|
||||
try {
|
||||
preInit = CompatModule.class.getMethod("preInit");
|
||||
CompatModule.class.getMethod("init");
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void preInit() {
|
||||
callAllForClass(PreInit.class);
|
||||
}
|
||||
public static void init() {
|
||||
callAllForClass(Init.class);
|
||||
}
|
||||
|
||||
private static void callAllForClass(Class c) {
|
||||
Method[] methods = c.getDeclaredMethods();
|
||||
for (Method m : methods) {
|
||||
if (m.getReturnType() == void.class && m.getParameterCount() == 0) {
|
||||
for (Map.Entry<String, Class<? extends CompatModule>> e:modules.entrySet()) {
|
||||
if (Loader.isModLoaded(e.getKey())) {
|
||||
try {
|
||||
m.setAccessible(true);
|
||||
m.invoke(null);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
preInit.invoke(e.getValue().newInstance());
|
||||
} catch (IllegalAccessException | InvocationTargetException | InstantiationException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class PreInit {
|
||||
@Optional.Method(modid = "crafttweaker")
|
||||
private static void preInitCraftTweaker() {
|
||||
public static void init() {
|
||||
for (Map.Entry<String, Class<? extends CompatModule>> e:modules.entrySet()) {
|
||||
if (Loader.isModLoaded(e.getKey())) {
|
||||
try {
|
||||
init.invoke(e.getValue().newInstance());
|
||||
} catch (IllegalAccessException | InvocationTargetException | InstantiationException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static abstract class CompatModule {
|
||||
public void preInit() {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
}
|
||||
|
||||
private static class CompatCT extends CompatModule {
|
||||
@Override
|
||||
public void preInit() {
|
||||
CraftTweakerAPI.registerClass(CTMarxGenerator.class);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Init {
|
||||
@Optional.Method(modid = "ic2")
|
||||
private static void initIC2() {
|
||||
private static class CompatIC2 extends CompatModule {
|
||||
public void init() {
|
||||
Item tinnedFood = IC2Items.getItem("filled_tin_can").getItem();
|
||||
ItemStack emptyMug = IC2Items.getItem("mug", "empty");
|
||||
ToolboxHandler.addFoodType((s) -> s.getItem() == tinnedFood);
|
||||
|
@ -76,6 +114,9 @@ public class Compat {
|
|||
Item a = s.getItem();
|
||||
return a instanceof IBoxable && ((IBoxable) a).canBeStoredInToolbox(s);
|
||||
});
|
||||
MechPartCommutator.originalStack = IC2Items.getItem("te", "kinetic_generator");
|
||||
loadIC2Tile = (te) -> MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent((IEnergyTile) te));
|
||||
unloadIC2Tile = (te) -> MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent((IEnergyTile) te));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,8 @@ import malte0811.industrialWires.util.LocalSidedWorld;
|
|||
import malte0811.industrialWires.util.MiscUtils;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
@ -56,6 +58,7 @@ import static malte0811.industrialWires.util.NBTKeys.TYPE;
|
|||
public abstract class MechMBPart {
|
||||
public static final Map<String, MechMBPart> INSTANCES = new HashMap<>();
|
||||
public LocalSidedWorld world;
|
||||
protected Map<BlockPos, IBlockState> original = new HashMap<>();
|
||||
|
||||
// These 3 are called once per tick in bulk in this order
|
||||
public abstract void createMEnergy(MechEnergy e);
|
||||
|
@ -91,12 +94,18 @@ public abstract class MechMBPart {
|
|||
return true;
|
||||
}
|
||||
|
||||
public abstract short getFormPattern();
|
||||
public abstract short getFormPattern(int offset);
|
||||
|
||||
/**
|
||||
* @param failed whether the MB is being disassembled because this part failed
|
||||
*/
|
||||
public abstract void disassemble(boolean failed, MechEnergy energy);
|
||||
public abstract void breakOnFailure(MechEnergy energy);
|
||||
|
||||
public ItemStack getOriginalItem(BlockPos pos) {
|
||||
IBlockState state = getOriginalBlock(pos);
|
||||
return new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state));
|
||||
}
|
||||
|
||||
public IBlockState getOriginalBlock(BlockPos pos) {
|
||||
return original.getOrDefault(pos, Blocks.AIR.getDefaultState());
|
||||
}
|
||||
|
||||
public abstract MechanicalMBBlockType getType();
|
||||
|
||||
|
@ -112,9 +121,19 @@ public abstract class MechMBPart {
|
|||
|
||||
public static final String SHAFT_KEY = "shaft";
|
||||
|
||||
public static final Comparator<MechMBPart> SORT_BY_COUNT = Comparator.comparingInt(
|
||||
(c)->-MiscUtils.count1Bits(c.getFormPattern())
|
||||
);
|
||||
public static final Comparator<MechMBPart> SORT_BY_COUNT = (a, b)-> {
|
||||
if (a.getLength()!=b.getLength()) {
|
||||
return Integer.compare(a.getLength(), b.getLength());
|
||||
}
|
||||
for (int i = 0;i<a.getLength();i++) {
|
||||
int aBits = MiscUtils.count1Bits(a.getFormPattern(i));
|
||||
int bBits = MiscUtils.count1Bits(b.getFormPattern(i));
|
||||
if (aBits!=bBits) {
|
||||
return Integer.compare(aBits, bBits);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
public static void preInit() {
|
||||
REGISTRY.put("flywheel", MechPartFlywheel.class);
|
||||
REGISTRY.put("singleCoil", MechPartSingleCoil.class);
|
||||
|
@ -177,33 +196,48 @@ public abstract class MechMBPart {
|
|||
state.getValue(IEContent.blockMetalDecoration0.property)==BlockTypes_MetalDecoration0.LIGHT_ENGINEERING;
|
||||
}
|
||||
|
||||
public void setDefaultShaft(BlockPos pos) {
|
||||
world.setBlockState(pos, blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property,
|
||||
HEAVY_ENGINEERING));
|
||||
public IBlockState getDefaultShaft() {
|
||||
return blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property,
|
||||
HEAVY_ENGINEERING);
|
||||
}
|
||||
|
||||
public void setLightEngineering(BlockPos pos) {
|
||||
world.setBlockState(pos, blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property,
|
||||
LIGHT_ENGINEERING));
|
||||
public IBlockState getLightEngineering() {
|
||||
return blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property,
|
||||
LIGHT_ENGINEERING);
|
||||
}
|
||||
|
||||
|
||||
public void form(LocalSidedWorld w, Consumer<TileEntityMechMB> initializer) {
|
||||
world = w;
|
||||
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain();
|
||||
short pattern = getFormPattern();
|
||||
int i = 0;
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
if ((pattern & (1 << i)) != 0) {
|
||||
pos.setPos(x, y, 0);
|
||||
w.setBlockState(pos, IndustrialWires.mechanicalMB.getStateFromMeta((i==4?getType():NO_MODEL).ordinal()));
|
||||
TileEntity te = w.getTileEntity(pos);
|
||||
if (te instanceof TileEntityMechMB) {
|
||||
initializer.accept((TileEntityMechMB) te);
|
||||
for (int z = 0;z<getLength();z++) {
|
||||
short pattern = getFormPattern(z);
|
||||
int i = 0;
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
if ((pattern & (1 << i)) != 0) {
|
||||
pos.setPos(x, y, -z);
|
||||
w.setBlockState(pos, IndustrialWires.mechanicalMB.getStateFromMeta((i == 4 ? getType() : NO_MODEL).ordinal()));
|
||||
TileEntity te = w.getTileEntity(pos);
|
||||
if (te instanceof TileEntityMechMB) {
|
||||
initializer.accept((TileEntityMechMB) te);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
pos.release();
|
||||
}
|
||||
|
||||
public void disassemble() {
|
||||
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain();
|
||||
for (int z = 0;z<getLength();z++) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
pos.setPos(x, y, -z);
|
||||
world.setBlockState(pos, getOriginalBlock(pos));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
pos.release();
|
||||
|
|
|
@ -22,6 +22,7 @@ import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
|||
import malte0811.industrialWires.converter.EUCapability.IC2EnergyHandler;
|
||||
import malte0811.industrialWires.util.ConversionUtil;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
@ -47,6 +48,7 @@ import static net.minecraft.util.math.BlockPos.ORIGIN;
|
|||
import static net.minecraftforge.energy.CapabilityEnergy.ENERGY;
|
||||
|
||||
public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
|
||||
public static ItemStack originalStack = ItemStack.EMPTY;
|
||||
private double bufferToMB;
|
||||
private Waveform wfToMB = Waveform.forParameters(NONE, get(has4Phases()), ROTATION);
|
||||
private double bufferToWorld;
|
||||
|
@ -259,13 +261,24 @@ public class MechPartCommutator extends MechMBPart implements IMBPartElectric {
|
|||
}
|
||||
|
||||
@Override
|
||||
public short getFormPattern() {
|
||||
public short getFormPattern(int offset) {
|
||||
return 0b000_010_000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disassemble(boolean failed, MechEnergy energy) {
|
||||
if (!failed&&IndustrialWires.ic2TeBlock!=null) {
|
||||
public void breakOnFailure(MechEnergy energy) {
|
||||
//NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOriginalItem(BlockPos pos) {
|
||||
return pos.equals(ORIGIN)?originalStack:super.getOriginalItem(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
|
|
|
@ -21,6 +21,7 @@ import malte0811.industrialWires.IndustrialWires;
|
|||
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
@ -34,6 +35,14 @@ import static net.minecraft.util.EnumFacing.EAST;
|
|||
import static net.minecraft.util.EnumFacing.WEST;
|
||||
|
||||
public class MechPartCommutator4Phase extends MechPartCommutator {
|
||||
{
|
||||
IBlockState lightEng = getLightEngineering();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
original.put(new BlockPos(2*i-1, j-1, 0), lightEng);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected double getMaxBuffer() {
|
||||
return 8*super.getMaxBuffer();
|
||||
|
@ -51,20 +60,10 @@ public class MechPartCommutator4Phase extends MechPartCommutator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public short getFormPattern() {
|
||||
public short getFormPattern(int offset) {
|
||||
return 0b000_111_101;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disassemble(boolean failed, MechEnergy energy) {
|
||||
super.disassemble(failed, energy);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
setLightEngineering(new BlockPos(2*i-1, j-1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MechanicalMBBlockType getType() {
|
||||
return MechanicalMBBlockType.SHAFT_COMMUTATOR_4;
|
||||
|
|
|
@ -38,6 +38,8 @@ import net.minecraftforge.oredict.OreDictionary;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.minecraft.util.math.BlockPos.ORIGIN;
|
||||
|
||||
public class MechPartFlywheel extends MechMBPart {
|
||||
private static final double RADIUS = 1.25;
|
||||
private static final double THICKNESS = 1;
|
||||
|
@ -124,17 +126,23 @@ public class MechPartFlywheel extends MechMBPart {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void disassemble(boolean failed, MechEnergy energy) {
|
||||
setDefaultShaft(BlockPos.ORIGIN);
|
||||
IBlockState state = Blocks.AIR.getDefaultState();
|
||||
if (!failed) {
|
||||
for (ItemStack block: OreDictionary.getOres("block"+material.oreName())) {
|
||||
if (block.getItem() instanceof ItemBlock) {
|
||||
ItemBlock ib = (ItemBlock) block.getItem();
|
||||
state = ib.getBlock().getStateFromMeta(block.getMetadata());
|
||||
}
|
||||
public IBlockState getOriginalBlock(BlockPos pos) {
|
||||
if (pos.equals(ORIGIN)) {
|
||||
return getDefaultShaft();
|
||||
}
|
||||
for (ItemStack block: OreDictionary.getOres("block"+material.oreName())) {
|
||||
if (block.getItem() instanceof ItemBlock) {
|
||||
ItemBlock ib = (ItemBlock) block.getItem();
|
||||
return ib.getBlock().getStateFromMeta(block.getMetadata());
|
||||
}
|
||||
}
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakOnFailure(MechEnergy energy) {
|
||||
world.setBlockState(ORIGIN, getDefaultShaft());
|
||||
IBlockState state = Blocks.AIR.getDefaultState();
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
if (x != 0 || y != 0) {
|
||||
|
@ -142,13 +150,11 @@ public class MechPartFlywheel extends MechMBPart {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
spawnBrokenParts(8, energy, material.blockTexture);
|
||||
}
|
||||
spawnBrokenParts(8, energy, material.blockTexture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getFormPattern() {
|
||||
public short getFormPattern(int offset) {
|
||||
return 0b111_111_111;
|
||||
}
|
||||
|
||||
|
@ -159,7 +165,7 @@ public class MechPartFlywheel extends MechMBPart {
|
|||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(BlockPos offsetPart) {
|
||||
if (BlockPos.ORIGIN.equals(offsetPart)) {
|
||||
if (ORIGIN.equals(offsetPart)) {
|
||||
return Block.FULL_BLOCK_AABB;
|
||||
}
|
||||
final double small = .375;
|
||||
|
|
|
@ -18,10 +18,18 @@ package malte0811.industrialWires.converter;
|
|||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import static net.minecraft.util.math.BlockPos.ORIGIN;
|
||||
|
||||
public class MechPartFourCoils extends MechPartSingleCoil {
|
||||
{
|
||||
IBlockState coil = getCoil();
|
||||
original.put(new BlockPos(-1, 0, 0), coil);
|
||||
original.put(new BlockPos(1, 0, 0), coil);
|
||||
}
|
||||
@Override
|
||||
protected double getMaxBuffer() {
|
||||
return 8*super.getMaxBuffer();
|
||||
|
@ -59,23 +67,20 @@ public class MechPartFourCoils extends MechPartSingleCoil {
|
|||
}
|
||||
|
||||
@Override
|
||||
public short getFormPattern() {
|
||||
public short getFormPattern(int offset) {
|
||||
return 0b111_111_111;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disassemble(boolean failed, MechEnergy energy) {
|
||||
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain(0, 0, 0);
|
||||
setDefaultShaft(pos);
|
||||
public void breakOnFailure(MechEnergy energy) {
|
||||
world.setBlockState(ORIGIN, getDefaultShaft());
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
pos.setPos(2 * i - 1, 2 * j - 1, 0);
|
||||
setLightEngineering(pos);
|
||||
pos.setPos((j == 0) ? 2 * i - 1 : 0, (j != 0) ? 2 * i - 1 : 0, 0);
|
||||
setCoil(pos);
|
||||
BlockPos pos = new BlockPos(2 * i - 1, 2 * j - 1, 0);
|
||||
world.setBlockState(pos, getLightEngineering());
|
||||
}
|
||||
}
|
||||
pos.release();
|
||||
spawnBrokenParts(8, energy, COIL_TEXTURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,7 @@ import malte0811.industrialWires.IndustrialWires;
|
|||
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
@ -34,6 +35,14 @@ import static net.minecraft.util.EnumFacing.EAST;
|
|||
import static net.minecraft.util.EnumFacing.WEST;
|
||||
|
||||
public class MechPartFourElectrodes extends MechPartTwoElectrodes {
|
||||
{
|
||||
IBlockState lightEng = getLightEngineering();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
original.put(new BlockPos(2*i-1, j-1, 0), lightEng);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected double getMaxBuffer() {
|
||||
return 8*super.getMaxBuffer();
|
||||
|
@ -51,20 +60,10 @@ public class MechPartFourElectrodes extends MechPartTwoElectrodes {
|
|||
}
|
||||
|
||||
@Override
|
||||
public short getFormPattern() {
|
||||
public short getFormPattern(int offset) {
|
||||
return 0b000_111_101;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disassemble(boolean failed, MechEnergy energy) {
|
||||
super.disassemble(failed, energy);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
setLightEngineering(new BlockPos(2*i-1, j-1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Set<Pair<BlockPos, EnumFacing>> outputs = ImmutableSet.of(
|
||||
new ImmutablePair<>(new BlockPos(1, 0, 0), EAST),
|
||||
new ImmutablePair<>(new BlockPos(1, -1, 0), EAST),
|
||||
|
|
|
@ -26,6 +26,9 @@ import net.minecraft.util.math.BlockPos;
|
|||
import static malte0811.industrialWires.blocks.converter.MechanicalMBBlockType.SHAFT_BASIC;
|
||||
|
||||
public class MechPartShaft extends MechMBPart {
|
||||
{
|
||||
original.put(BlockPos.ORIGIN, getDefaultShaft());
|
||||
}
|
||||
@Override
|
||||
public void createMEnergy(MechEnergy e) {}
|
||||
|
||||
|
@ -64,13 +67,13 @@ public class MechPartShaft extends MechMBPart {
|
|||
}
|
||||
|
||||
@Override
|
||||
public short getFormPattern() {
|
||||
public short getFormPattern(int offset) {
|
||||
return 0b000_010_000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disassemble(boolean failed, MechEnergy energy) {
|
||||
setDefaultShaft(BlockPos.ORIGIN);
|
||||
public void breakOnFailure(MechEnergy energy) {
|
||||
disassemble();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,8 +32,20 @@ import static blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_Met
|
|||
import static malte0811.industrialWires.converter.Waveform.Phases.get;
|
||||
import static malte0811.industrialWires.util.NBTKeys.BUFFER_IN;
|
||||
import static malte0811.industrialWires.util.NBTKeys.BUFFER_OUT;
|
||||
import static net.minecraft.util.math.BlockPos.ORIGIN;
|
||||
|
||||
public class MechPartSingleCoil extends MechMBPart implements IMBPartElectric {
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
private double bufferToMech;
|
||||
private double bufferToE;
|
||||
|
||||
|
@ -117,8 +129,8 @@ public class MechPartSingleCoil extends MechMBPart implements IMBPartElectric {
|
|||
state.getValue(blockMetalDecoration0.property) == BlockTypes_MetalDecoration0.COIL_LV;
|
||||
}
|
||||
|
||||
protected void setCoil(BlockPos p) {
|
||||
world.setBlockState(p, blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property, COIL_LV));
|
||||
protected IBlockState getCoil() {
|
||||
return blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property, COIL_LV);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -151,28 +163,21 @@ public class MechPartSingleCoil extends MechMBPart implements IMBPartElectric {
|
|||
}
|
||||
|
||||
@Override
|
||||
public short getFormPattern() {
|
||||
public short getFormPattern(int offset) {
|
||||
return 0b111_111_111;
|
||||
}
|
||||
|
||||
private static final ResourceLocation COIL_TEXTURE = new ResourceLocation(ImmersiveEngineering.MODID,
|
||||
protected static final ResourceLocation COIL_TEXTURE = new ResourceLocation(ImmersiveEngineering.MODID,
|
||||
"blocks/metal_decoration0_coil_lv_side");
|
||||
@Override
|
||||
public void disassemble(boolean failed, MechEnergy energy) {
|
||||
setDefaultShaft(BlockPos.ORIGIN);
|
||||
if (!failed) {
|
||||
for (int i = -1;i<=1;i+=2) {
|
||||
setCoil(BlockPos.ORIGIN.up(i));
|
||||
}
|
||||
} else {
|
||||
int count = has4Phases()?8:2;
|
||||
spawnBrokenParts(count, energy, COIL_TEXTURE);
|
||||
}
|
||||
public void breakOnFailure(MechEnergy energy) {
|
||||
world.setBlockState(ORIGIN, getDefaultShaft());
|
||||
for (int i = -1; i <= 1; i+=2) {
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
setLightEngineering(new BlockPos(i, y, 0));
|
||||
world.setBlockState(new BlockPos(i, y, 0), getLightEngineering());
|
||||
}
|
||||
}
|
||||
spawnBrokenParts(8, energy, COIL_TEXTURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,6 +27,7 @@ import malte0811.industrialWires.util.LocalSidedWorld;
|
|||
import malte0811.industrialWires.util.NBTKeys;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
@ -53,6 +54,10 @@ public class MechPartSpeedometer extends MechMBPart implements IPlayerInteractio
|
|||
private int currentOutputLin = -1;
|
||||
private int currentOutputLog = -1;
|
||||
private double logFactor = 15 / Math.log(speedFor15RS + 1);
|
||||
{
|
||||
original.put(ORIGIN, blockMetalDecoration0
|
||||
.getStateFromMeta(RS_ENGINEERING.getMeta()));
|
||||
}
|
||||
@Nullable
|
||||
private MechEnergy energy = null;
|
||||
|
||||
|
@ -128,14 +133,13 @@ public class MechPartSpeedometer extends MechMBPart implements IPlayerInteractio
|
|||
}
|
||||
|
||||
@Override
|
||||
public short getFormPattern() {
|
||||
public short getFormPattern(int offset) {
|
||||
return 0b000_010_000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disassemble(boolean failed, MechEnergy energy) {
|
||||
world.setBlockState(ORIGIN, blockMetalDecoration0
|
||||
.getStateFromMeta(RS_ENGINEERING.getMeta()));
|
||||
public void breakOnFailure(MechEnergy energy) {
|
||||
world.setBlockState(ORIGIN, Blocks.AIR.getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,6 +50,11 @@ public class MechPartTwoElectrodes extends MechMBPart implements IMBPartElectric
|
|||
private double bufferToWorld;
|
||||
private Waveform wfToWorld = Waveform.forParameters(Waveform.Type.NONE, get(has4Phases()), Waveform.Speed.ROTATION);
|
||||
|
||||
{
|
||||
original.put(ORIGIN, blockMetalDecoration0.getDefaultState().withProperty(
|
||||
blockMetalDecoration0.property, GENERATOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Waveform getProduced(MechEnergy state) {
|
||||
return wfToMB;
|
||||
|
@ -139,14 +144,13 @@ public class MechPartTwoElectrodes extends MechMBPart implements IMBPartElectric
|
|||
}
|
||||
|
||||
@Override
|
||||
public short getFormPattern() {
|
||||
public short getFormPattern(int offset) {
|
||||
return 0b000_010_000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disassemble(boolean failed, MechEnergy energy) {
|
||||
world.setBlockState(ORIGIN,
|
||||
blockMetalDecoration0.getDefaultState().withProperty(blockMetalDecoration0.property, GENERATOR));
|
||||
public void breakOnFailure(MechEnergy energy) {
|
||||
//NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,6 @@ import malte0811.industrialWires.IndustrialWires;
|
|||
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
|
||||
import malte0811.industrialWires.blocks.converter.TileEntityMechMB;
|
||||
import malte0811.industrialWires.util.LocalSidedWorld;
|
||||
import malte0811.industrialWires.util.MiscUtils;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -91,15 +90,15 @@ public class MultiblockMechMB implements MultiblockHandler.IMultiblock {
|
|||
w.setOrigin(w.getRealPos(mutPos));
|
||||
MechMBPart next = null;
|
||||
List<MechMBPart> instances = new ArrayList<>(MechMBPart.INSTANCES.values());
|
||||
instances.sort(MechMBPart.SORT_BY_COUNT);
|
||||
int lastCount = 0;
|
||||
instances.sort(MechMBPart.SORT_BY_COUNT.reversed());
|
||||
MechMBPart last = instances.get(0);
|
||||
for (MechMBPart part:instances) {
|
||||
int newCount = MiscUtils.count1Bits(part.getFormPattern());
|
||||
if (newCount==1&&lastCount>1&&checkEnd(w, mutPos)) {
|
||||
if (MechMBPart.SORT_BY_COUNT.compare(last, part)!=0&&
|
||||
checkEnd(w, mutPos)) {
|
||||
foundAll = true;
|
||||
break;
|
||||
}
|
||||
lastCount = newCount;
|
||||
last = part;
|
||||
if (part.canForm(w)) {
|
||||
next = part;
|
||||
String key = MechMBPart.REGISTRY.inverse().get(part.getClass());
|
||||
|
|
|
@ -19,14 +19,12 @@ import blusunrize.immersiveengineering.ImmersiveEngineering;
|
|||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
|
||||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
|
||||
import blusunrize.immersiveengineering.common.util.Utils;
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -142,14 +140,6 @@ public final class MiscUtils {
|
|||
return new AxisAlignedBB(min.x, min.y, min.z, max.x, max.y, max.z);
|
||||
}
|
||||
|
||||
public static ItemStack getItemStack(IBlockState origState, World w, BlockPos pos) {
|
||||
if (origState.getBlock() instanceof IEBlockInterfaces.IIEMetaBlock) {
|
||||
int meta = origState.getBlock().getMetaFromState(origState);
|
||||
return new ItemStack(origState.getBlock(), 1, meta);
|
||||
}
|
||||
return origState.getBlock().getPickBlock(origState, null, w, pos, null);
|
||||
}
|
||||
|
||||
public static float[] interpolate(double a, float[] cA, double b, float[] cB) {
|
||||
float[] ret = new float[cA.length];
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
|
|
Loading…
Reference in a new issue