Finished the separated energy inputs/outputs. Textures will need to change since they get blocked by most pipes/connectors
This commit is contained in:
parent
3d2865aa93
commit
311a498a90
|
@ -101,4 +101,24 @@ public class BlockMechanicalMB extends BlockIWMultiblock implements IMetaEnum {
|
|||
public Object[] getValues() {
|
||||
return TYPE.getAllowedValues().toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
|
||||
if ((id&255)==255) {
|
||||
IBlockState s = worldIn.getBlockState(pos);
|
||||
worldIn.notifyBlockUpdate(pos, s, s, 3);
|
||||
if (param>=0) {
|
||||
TileEntity te = worldIn.getTileEntity(pos);
|
||||
if (te instanceof TileEntityMechMB && !((TileEntityMechMB) te).isLogicDummy()) {
|
||||
int[] offsets = ((TileEntityMechMB) te).offsets;
|
||||
if (offsets!=null && param<offsets.length) {
|
||||
BlockPos otherPos = pos.offset(((TileEntityMechMB) te).getFacing(), -offsets[param]);
|
||||
s = worldIn.getBlockState(otherPos);
|
||||
worldIn.notifyBlockUpdate(otherPos, s, s, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.eventReceived(state, worldIn, pos, id, param);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerIn
|
|||
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IRedstoneOutput;
|
||||
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0;
|
||||
import blusunrize.immersiveengineering.common.util.Utils;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergyEmitter;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
@ -72,8 +73,9 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
private static final double DECAY_BASE = Math.exp(Math.log(.95) / (60 * 60 * 20));
|
||||
public static final double TICK_ANGLE_PER_SPEED = 180 / 20 / Math.PI;
|
||||
private static final double SYNC_THRESHOLD = .95;
|
||||
private static final Map<BlockPos, TileEntityMechMB> CLIENT_MASTER_BY_POS = new MapMaker().weakValues().makeMap();
|
||||
public MechMBPart[] mechanical = null;
|
||||
private int[] offsets = null;
|
||||
public int[] offsets = null;
|
||||
|
||||
private int[][] electricalStartEnd = null;
|
||||
|
||||
|
@ -90,7 +92,7 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
@Override
|
||||
public void update() {
|
||||
ApiUtils.checkForNeedlessTicking(this);
|
||||
if (firstTick) {
|
||||
if (firstTick && !world.isRemote) {
|
||||
Compat.loadIC2Tile.accept(this);
|
||||
firstTick = false;
|
||||
}
|
||||
|
@ -100,6 +102,9 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
if (world.isRemote) {
|
||||
angle += energyState.getSpeed() * TICK_ANGLE_PER_SPEED;
|
||||
angle %= 360;
|
||||
if (firstTick) {
|
||||
CLIENT_MASTER_BY_POS.put(pos, this);
|
||||
}
|
||||
if (energyState.clientUpdate()||firstTick) {
|
||||
IndustrialWires.proxy.updateMechMBTurningSound(this, energyState);
|
||||
int otherEndOffset = offsets[offsets.length-1]+mechanical[mechanical.length-1].getLength();
|
||||
|
@ -108,8 +113,6 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
IndustrialWires.proxy.updateMechMBTurningSound((TileEntityMechMB) otherEnd, energyState);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
// Mechanical
|
||||
|
@ -226,9 +229,11 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
}
|
||||
}
|
||||
|
||||
public IBlockState getExtState(IBlockState in) {//TODO make this work with multithreading
|
||||
public IBlockState getExtState(IBlockState in) {
|
||||
TileEntityMechMB master = CLIENT_MASTER_BY_POS.get(pos.subtract(offset));
|
||||
if (master==null)
|
||||
return in;
|
||||
Vec3i offsetDirectional = getOffsetDir();
|
||||
TileEntityMechMB master = masterOr(this, this);
|
||||
int id = getPart(offsetDirectional.getZ(), master);
|
||||
if (id < 0) {
|
||||
return in;
|
||||
|
@ -586,6 +591,8 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
public void invalidate() {
|
||||
if (!world.isRemote && !firstTick)
|
||||
Compat.unloadIC2Tile.accept(this);
|
||||
else if (world.isRemote)
|
||||
CLIENT_MASTER_BY_POS.remove(pos);
|
||||
firstTick = true;
|
||||
super.invalidate();
|
||||
}
|
||||
|
@ -595,7 +602,9 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
super.onChunkUnload();
|
||||
if (!world.isRemote && !firstTick)
|
||||
Compat.unloadIC2Tile.accept(this);
|
||||
firstTick = true;
|
||||
else if (world.isRemote)
|
||||
CLIENT_MASTER_BY_POS.remove(pos);
|
||||
firstTick = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -606,9 +615,14 @@ public class TileEntityMechMB extends TileEntityIWMultiblock implements ITickabl
|
|||
if (id >= 0) {
|
||||
MechMBPart part = master.mechanical[id];
|
||||
side = part.world.realToTransformed(side);
|
||||
if (part.interact(side, getOffsetDir().add(0, 0, - master.offsets[id]),
|
||||
player, hand, heldItem)) {
|
||||
master.triggerRenderUpdate();
|
||||
int ret = part.interact(side, getOffsetDir().add(0, 0, - master.offsets[id]),
|
||||
player, hand, heldItem);
|
||||
if (ret>=0) {
|
||||
if ((ret&1)!=0) {
|
||||
IBlockState state = world.getBlockState(master.pos);
|
||||
world.notifyBlockUpdate(master.pos, state, state, 3);
|
||||
world.addBlockEvent(master.pos, state.getBlock(), 255, id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,10 @@ import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
|||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
@ -46,6 +48,7 @@ import javax.annotation.Nullable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
@ -57,16 +60,14 @@ public class BakedMBIOModel implements IBakedModel {
|
|||
static TextureAtlasSprite IO_TEX = null;
|
||||
|
||||
private final IBakedModel base;
|
||||
private final int rotationInt;
|
||||
private final Rotation rotation;
|
||||
private final TRSRTransformation transform;
|
||||
|
||||
private final Cache<MBSideConfig, List<BakedQuad>> cache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.MINUTES)
|
||||
.maximumSize(100).build();
|
||||
|
||||
BakedMBIOModel(IBakedModel base, int rotationOffset) {
|
||||
BakedMBIOModel(IBakedModel base, IModelState transform) {
|
||||
this.base = base;
|
||||
this.rotationInt = rotationOffset;
|
||||
this.rotation = Rotation.values()[rotationOffset];
|
||||
this.transform = TRSRTransformation.blockCornerToCenter(transform.apply(Optional.empty()).orElse(TRSRTransformation.identity()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@ -84,18 +85,16 @@ public class BakedMBIOModel implements IBakedModel {
|
|||
if (IO_TEX==null) {
|
||||
IO_TEX = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(IO_LOC.toString());
|
||||
}
|
||||
Matrix4 mat = new Matrix4(transform.getMatrix());
|
||||
ret = new ArrayList<>(base.getQuads(state, side, rand));
|
||||
for (Map.Entry<BlockFace, SideConfig> f:config.sides.entrySet()) {
|
||||
if (f.getKey().face==null) {
|
||||
continue;
|
||||
}
|
||||
BlockPos transformedPos = f.getKey().offset.rotate(rotation);
|
||||
EnumFacing transformedFace = f.getKey().face;
|
||||
if (transformedFace.getAxis()!=EnumFacing.Axis.Y) {
|
||||
for (int i = 0; i < rotationInt; i++) {
|
||||
transformedFace = transformedFace.rotateY();
|
||||
}
|
||||
}
|
||||
Vec3d transformedPos = mat.apply(new Vec3d(f.getKey().offset));
|
||||
EnumFacing transformedFace = transform.rotate(f.getKey().face);
|
||||
IndustrialWires.logger.info("Transformed {} and {} to {} and {} ({})", f.getKey().offset, f.getKey().face,
|
||||
transformedPos, transformedFace);
|
||||
Vector3f[] verts = getVerticesFromFace(transformedPos, transformedFace);
|
||||
RawQuad q = new RawQuad(verts[0], verts[1], verts[2], verts[3], transformedFace,
|
||||
IO_TEX, new float[]{1, 1, 1, 1}, getNormal(transformedFace),
|
||||
|
@ -130,10 +129,10 @@ public class BakedMBIOModel implements IBakedModel {
|
|||
return new Vector3f(in[0], in[1], in[2]);
|
||||
}
|
||||
|
||||
private Vector3f[] getVerticesFromFace(BlockPos p, EnumFacing f) {
|
||||
private Vector3f[] getVerticesFromFace(Vec3d p, EnumFacing f) {
|
||||
Vector3f[] orig = VERTICES[f.ordinal()];
|
||||
Vector3f[] ret = new Vector3f[4];
|
||||
Vector3f offset = new Vector3f(p.getX(), p.getY(), p.getZ());
|
||||
Vector3f offset = new Vector3f((float) p.x, (float) p.y, (float) p.z);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
ret[i] = Vector3f.add(orig[i], offset, null);
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ public class MBIOModelLoader implements ICustomModelLoader {
|
|||
);
|
||||
private ResourceLocation baseModel = new ResourceLocation(IndustrialWires.MODID, "missing");
|
||||
private ImmutableMap<String, String> custom = ImmutableMap.of();
|
||||
private int rotationOffset = 0;
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
|
@ -89,13 +88,14 @@ public class MBIOModelLoader implements ICustomModelLoader {
|
|||
|
||||
@Nonnull
|
||||
@Override
|
||||
@SideOnly(CLIENT)
|
||||
public IBakedModel bake(@Nonnull IModelState state, @Nonnull VertexFormat format,
|
||||
@Nonnull Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
|
||||
try {
|
||||
IModel baseBaked = ModelLoaderRegistry.getModel(baseModel);
|
||||
baseBaked = baseBaked.process(custom);
|
||||
IBakedModel baked = baseBaked.bake(state, format, bakedTextureGetter);
|
||||
BakedMBIOModel ret = new BakedMBIOModel(baked, rotationOffset);
|
||||
BakedMBIOModel ret = new BakedMBIOModel(baked, state);
|
||||
activeModels.add(ret);
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
|
@ -110,10 +110,6 @@ public class MBIOModelLoader implements ICustomModelLoader {
|
|||
MBIOModel ret = new MBIOModel();
|
||||
String bm = customData.get("base_model");
|
||||
ret.baseModel = new ResourceLocation(bm.substring(1, bm.length()-1));
|
||||
String rotOffsetTmp = customData.get("rotation_offset");
|
||||
if (rotOffsetTmp!=null) {
|
||||
ret.rotationOffset = Integer.parseInt(rotOffsetTmp)&3;
|
||||
}
|
||||
ret.custom = customData;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -128,9 +128,9 @@ public abstract class MechMBPart {
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean interact(@Nonnull EnumFacing side, @Nonnull Vec3i offset, @Nonnull EntityPlayer player,
|
||||
@Nonnull EnumHand hand, @Nonnull ItemStack heldItem) {
|
||||
return false;
|
||||
public int interact(@Nonnull EnumFacing side, @Nonnull Vec3i offset, @Nonnull EntityPlayer player,
|
||||
@Nonnull EnumHand hand, @Nonnull ItemStack heldItem) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static final BiMap<String, Class<? extends MechMBPart>> REGISTRY = HashBiMap.create();
|
||||
|
|
|
@ -169,8 +169,8 @@ public abstract class MechPartEnergyIO extends MechMBPart implements IMBPartElec
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean interact(@Nonnull EnumFacing side, @Nonnull Vec3i offset, @Nonnull EntityPlayer player,
|
||||
@Nonnull EnumHand hand, @Nonnull ItemStack heldItem) {
|
||||
public int interact(@Nonnull EnumFacing side, @Nonnull Vec3i offset, @Nonnull EntityPlayer player,
|
||||
@Nonnull EnumHand hand, @Nonnull ItemStack heldItem) {
|
||||
if (Utils.isHammer(heldItem)) {
|
||||
BlockFace s = new BlockFace(new BlockPos(offset), side);
|
||||
if (sides.isValid(s)) {
|
||||
|
@ -178,10 +178,10 @@ public abstract class MechPartEnergyIO extends MechMBPart implements IMBPartElec
|
|||
sides.cycleSide(s);
|
||||
world.markForUpdate(BlockPos.ORIGIN);
|
||||
}
|
||||
return true;
|
||||
return 0b11;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -158,7 +158,7 @@ public class MechPartSpeedometer extends MechMBPart implements IRedstoneOutput {
|
|||
private static DecimalFormat format = new DecimalFormat("###.000");
|
||||
|
||||
@Override
|
||||
public boolean interact(@Nonnull EnumFacing side, @Nonnull Vec3i offset, @Nonnull EntityPlayer player, @Nonnull EnumHand hand, @Nonnull ItemStack heldItem) {
|
||||
public int interact(@Nonnull EnumFacing side, @Nonnull Vec3i offset, @Nonnull EntityPlayer player, @Nonnull EnumHand hand, @Nonnull ItemStack heldItem) {
|
||||
if (voltMeter.isEmpty()) {
|
||||
voltMeter = new ItemStack(IEContent.itemTool, 1, ItemIETool.VOLTMETER_META);
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ public class MechPartSpeedometer extends MechMBPart implements IRedstoneOutput {
|
|||
speedFor15RS));
|
||||
update(true);
|
||||
}
|
||||
return true;
|
||||
return 0;
|
||||
} else if (OreDictionary.itemMatches(heldItem, voltMeter, false)) {
|
||||
if (!world.isRemote) {
|
||||
double speed = energy != null ? energy.getSpeed() : 0;
|
||||
|
@ -184,9 +184,9 @@ public class MechPartSpeedometer extends MechMBPart implements IRedstoneOutput {
|
|||
new TextComponentTranslation(IndustrialWires.MODID + ".chat.currSpeed",
|
||||
format.format(speed), format.format(speed * 60D / (2 * Math.PI))));
|
||||
}
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,6 +76,8 @@ public class MultiblockMechMB implements MultiblockHandler.IMultiblock {
|
|||
|
||||
@Override
|
||||
public boolean createStructure(World world, BlockPos pos, EnumFacing side, EntityPlayer player) {
|
||||
if (side.getAxis().isVertical())
|
||||
return false;
|
||||
BlockPos.PooledMutableBlockPos mutPos = BlockPos.PooledMutableBlockPos.retain();
|
||||
try {
|
||||
LocalSidedWorld w = new LocalSidedWorld(world, pos, side.getOpposite(), false);
|
||||
|
|
|
@ -43,29 +43,25 @@
|
|||
"shaft_commutator": {
|
||||
"model": "industrialwires:mbio",
|
||||
"custom": {
|
||||
"base_model": "industrialwires:block/mech_mb/commutator.obj",
|
||||
"rotation_offset": 3
|
||||
"base_model": "industrialwires:block/mech_mb/commutator.obj"
|
||||
}
|
||||
},
|
||||
"shaft_1_phase": {
|
||||
"model": "industrialwires:mbio",
|
||||
"custom": {
|
||||
"base_model": "industrialwires:block/mech_mb/two_electrodes.obj",
|
||||
"rotation_offset": 3
|
||||
"base_model": "industrialwires:block/mech_mb/two_electrodes.obj"
|
||||
}
|
||||
},
|
||||
"shaft_commutator_4": {
|
||||
"model": "industrialwires:mbio",
|
||||
"custom": {
|
||||
"base_model": "industrialwires:block/mech_mb/commutator4.obj",
|
||||
"rotation_offset": 3
|
||||
"base_model": "industrialwires:block/mech_mb/commutator4.obj"
|
||||
}
|
||||
},
|
||||
"shaft_4_phase": {
|
||||
"model": "industrialwires:mbio",
|
||||
"custom": {
|
||||
"base_model": "industrialwires:block/mech_mb/four_electrodes.obj",
|
||||
"rotation_offset": 3
|
||||
"base_model": "industrialwires:block/mech_mb/four_electrodes.obj"
|
||||
}
|
||||
},
|
||||
"speedometer": {
|
||||
|
|
Loading…
Reference in a new issue