TMP commit

This commit is contained in:
malte0811 2017-10-04 17:05:04 +02:00
parent e9449440fd
commit 58692ceb76
41 changed files with 1351 additions and 76 deletions

View file

@ -1,5 +1,5 @@
def mainVersion = "1.6"
def buildNumber = "20"
def buildNumber = "22"
// For those who want the bleeding edge
buildscript {
@ -69,13 +69,13 @@ repositories {
}
dependencies {
compileOnly 'net.industrial-craft:industrialcraft-2:2.8.+'
deobfCompile 'net.industrial-craft:industrialcraft-2:2.8.+'
deobfCompile "blusunrize:ImmersiveEngineering:0.12-+:deobf"
compileOnly "TechReborn:TechReborn-1.12:2.6.+:dev"
compileOnly "RebornCore:RebornCore-1.12:3.2.+:dev"
deobfCompile 'com.elytradev:mirage:2.0.1-SNAPSHOT'
deobfCompile "mezz.jei:jei_1.12:4.+"
deobfCompile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.+"
compileOnly "mezz.jei:jei_1.12:4.+"
compileOnly "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.0.10.306"
}
jar {

View file

@ -20,10 +20,7 @@ package malte0811.industrialWires;
import blusunrize.immersiveengineering.api.MultiblockHandler;
import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.controlpanel.*;
import malte0811.industrialWires.blocks.converter.BlockMechanicalConverter;
import malte0811.industrialWires.blocks.converter.TileEntityIEMotor;
import malte0811.industrialWires.blocks.converter.TileEntityMechICtoIE;
import malte0811.industrialWires.blocks.converter.TileEntityMechIEtoIC;
import malte0811.industrialWires.blocks.converter.*;
import malte0811.industrialWires.blocks.hv.BlockHVMultiblocks;
import malte0811.industrialWires.blocks.hv.BlockJacobsLadder;
import malte0811.industrialWires.blocks.hv.TileEntityJacobsLadder;
@ -31,6 +28,8 @@ import malte0811.industrialWires.blocks.hv.TileEntityMarx;
import malte0811.industrialWires.blocks.wire.*;
import malte0811.industrialWires.compat.Compat;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.converter.MechMBPart;
import malte0811.industrialWires.converter.MultiblockConverter;
import malte0811.industrialWires.crafting.Recipes;
import malte0811.industrialWires.hv.MarxOreHandler;
import malte0811.industrialWires.hv.MultiblockMarx;
@ -87,6 +86,8 @@ public class IndustrialWires {
public static BlockPanel panel = null;
@GameRegistry.ObjectHolder(MODID+":"+BlockHVMultiblocks.NAME)
public static BlockHVMultiblocks hvMultiblocks = null;
@GameRegistry.ObjectHolder(MODID+":"+BlockMechanicalMB.NAME)
public static BlockMechanicalMB mechanicalMB = null;
@GameRegistry.ObjectHolder(MODID+":"+ItemIC2Coil.NAME)
public static ItemIC2Coil coil = null;
@ -140,6 +141,7 @@ public class IndustrialWires {
GameRegistry.registerTileEntity(TileEntityMechIEtoIC.class, MODID + ":mechIeToIc");
}
}
GameRegistry.registerTileEntity(TileEntityMultiblockConverter.class, MODID + ":mechMB");//TODO respect enableConversion!
GameRegistry.registerTileEntity(TileEntityJacobsLadder.class, MODID + ":jacobsLadder");
GameRegistry.registerTileEntity(TileEntityMarx.class, MODID + ":marx_generator");
GameRegistry.registerTileEntity(TileEntityPanel.class, MODID + ":control_panel");
@ -165,6 +167,7 @@ public class IndustrialWires {
event.getRegistry().register(new BlockJacobsLadder());
event.getRegistry().register(new BlockPanel());
event.getRegistry().register(new BlockHVMultiblocks());
event.getRegistry().register(new BlockMechanicalMB());
}
@SubscribeEvent
@ -189,6 +192,8 @@ public class IndustrialWires {
public void init(FMLInitializationEvent e) {
MultiblockMarx.INSTANCE = new MultiblockMarx();
MultiblockHandler.registerMultiblock(MultiblockMarx.INSTANCE);
MultiblockConverter.INSTANCE = new MultiblockConverter();
MultiblockHandler.registerMultiblock(MultiblockConverter.INSTANCE);
packetHandler.registerMessage(MessageTileSyncIW.HandlerClient.class, MessageTileSyncIW.class, 0, Side.CLIENT);
packetHandler.registerMessage(MessagePanelInteract.HandlerServer.class, MessagePanelInteract.class, 1, Side.SERVER);
@ -199,6 +204,7 @@ public class IndustrialWires {
IWPotions.init();
Compat.init();
MarxOreHandler.init();
MechMBPart.init();
}
@EventHandler

View file

@ -25,9 +25,6 @@ import net.minecraft.tileentity.TileEntity;
import javax.annotation.Nonnull;
public abstract class TileEntityIWBase extends TileEntity {
protected static final String ENERGY_TAG = "energy";
protected static final String BUFFER_TAG = "buffer";
protected static final String DIR_TAG = "dir";
@Nonnull
@Override

View file

@ -18,7 +18,6 @@
package malte0811.industrialWires.blocks;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGeneralMultiblock;
import malte0811.industrialWires.util.MiscUtils;
import net.minecraft.block.state.IBlockState;
@ -42,7 +41,7 @@ public abstract class TileEntityIWMultiblock extends TileEntityIWBase implements
protected final static String FACING = "facing";
//HFR
protected Vec3i size;
public Vec3i offset = new Vec3i(0, 0, 0);
public Vec3i offset = new Vec3i(0, 1, 0);
public boolean formed;
public boolean mirrored;
public long onlyLocalDissassembly;

View file

@ -26,9 +26,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.MathHelper;
import static malte0811.industrialWires.util.NBTKeys.ANGLE;
import static malte0811.industrialWires.util.NBTKeys.HEIGHT;
public class ItemBlockPanel extends ItemBlockIW implements IConfigurableTool {
private static final String HEIGHT = "height";
private static final String ANGLE = "angle";
public ItemBlockPanel(Block b) {
super(b);

View file

@ -0,0 +1,57 @@
package malte0811.industrialWires.blocks.converter;
import blusunrize.immersiveengineering.api.IEProperties;
import malte0811.industrialWires.blocks.BlockIWMultiblock;
import malte0811.industrialWires.blocks.IMetaEnum;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BlockMechanicalMB extends BlockIWMultiblock implements IMetaEnum {
public static final PropertyEnum<MechanicalMBBlockType> TYPE = PropertyEnum.create("type", MechanicalMBBlockType.class);
public static final String NAME = "mech_mb";
public BlockMechanicalMB() {
super(Material.IRON, NAME);
}
@Override
protected IProperty[] getProperties() {
return new IProperty[] {
IEProperties.FACING_HORIZONTAL, TYPE
};
}
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}
@Nullable
@Override
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
return new TileEntityMultiblockConverter();
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(TYPE).ordinal();
}
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(TYPE, MechanicalMBBlockType.VALUES[meta]);
}
@Override
public Object[] getValues() {
return TYPE.getAllowedValues().toArray();
}
}

View file

@ -0,0 +1,22 @@
package malte0811.industrialWires.blocks.converter;
import net.minecraft.util.IStringSerializable;
public enum MechanicalMBBlockType implements IStringSerializable {
NO_MODEL,
END,
OTHER_END,
COIL_4_PHASE,
COIL_1_PHASE,
SHAFT_INSULATING,
SHAFT_4_PHASE,
SHAFT_1_PHASE,
SHAFT_COMMUTATOR,
FLYWHEEL;
public static final MechanicalMBBlockType[] VALUES = values();
@Override
public String getName() {
return name().toLowerCase();
}
}

View file

@ -36,6 +36,8 @@ import net.minecraftforge.energy.CapabilityEnergy;
import javax.annotation.Nonnull;
import static malte0811.industrialWires.util.NBTKeys.*;
public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IFluxReceiver, IDirectionalTile {
public final double bufferMax = 2 * MechConversion.maxIfToMech * ConversionUtil.rotPerIf();

View file

@ -32,6 +32,9 @@ import net.minecraft.util.math.BlockPos;
import javax.annotation.Nonnull;
import static malte0811.industrialWires.util.NBTKeys.BUFFER_TAG;
import static malte0811.industrialWires.util.NBTKeys.DIR_TAG;
public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirectionalTile, ITickable {
EnumFacing dir = EnumFacing.DOWN;
int kinBuffer = 0;

View file

@ -29,6 +29,9 @@ import net.minecraft.util.EnumFacing;
import javax.annotation.Nonnull;
import static malte0811.industrialWires.util.NBTKeys.BUFFER_TAG;
import static malte0811.industrialWires.util.NBTKeys.DIR_TAG;
public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirectionalTile, IRotationAcceptor, IKineticSource {
EnumFacing dir = EnumFacing.DOWN;
double rotBuffer = 0;

View file

@ -0,0 +1,145 @@
package malte0811.industrialWires.blocks.converter;
import blusunrize.immersiveengineering.api.ApiUtils;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.ISyncReceiver;
import malte0811.industrialWires.blocks.TileEntityIWMultiblock;
import malte0811.industrialWires.converter.MechEnergy;
import malte0811.industrialWires.converter.MechMBPart;
import malte0811.industrialWires.network.MessageTileSyncIW;
import malte0811.industrialWires.util.MiscUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import java.util.IdentityHashMap;
import java.util.List;
import static malte0811.industrialWires.util.NBTKeys.PARTS;
import static malte0811.industrialWires.util.NBTKeys.SPEED;
public class TileEntityMultiblockConverter extends TileEntityIWMultiblock implements ITickable, ISyncReceiver {
private static final double DECAY_BASE = .99;
public static final double TICK_ANGLE_PER_SPEED = 180/1e3;
private static final double SYNC_THRESHOLD = .999;
public MechMBPart[] mechanical;
public MechEnergy energyState;
private double lastSyncedSpeed = 0;
private double decay;
public double angle;
@SideOnly(Side.CLIENT)
public List<BakedQuad> rotatingModel;
@Override
public void update() {
ApiUtils.checkForNeedlessTicking(this);
if (world.isRemote&&mechanical!=null) {
angle += energyState.getSpeed()*TICK_ANGLE_PER_SPEED;
angle %= 360;
}
if (world.isRemote||isLogicDummy()||mechanical==null) {
return;
}
//energyState = new MechEnergy(energyState.weight, 10);
for (MechMBPart part:mechanical) {
part.produceRotation(energyState);
}
double requestSum = 0;
IdentityHashMap<MechMBPart, Double> individualRequests = new IdentityHashMap<>();
for (MechMBPart part:mechanical) {
double eForPart = part.requestEnergy(energyState);
requestSum += eForPart;
individualRequests.put(part, eForPart);
}
double availableEnergy = energyState.getEnergy();
double factor = (requestSum>availableEnergy)?availableEnergy/requestSum:1;
energyState.extractEnergy(factor*requestSum);
for (MechMBPart part:mechanical) {
part.consumeRotation(factor*individualRequests.get(part));
}
//TODO check for "overspeed"
energyState.decaySpeed(decay);
markDirty();
if (lastSyncedSpeed<energyState.getSpeed()*SYNC_THRESHOLD||lastSyncedSpeed>energyState.getSpeed()/SYNC_THRESHOLD) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setDouble(SPEED, energyState.getSpeed());
IndustrialWires.packetHandler.sendToDimension(new MessageTileSyncIW(this, nbt), world.provider.getDimension());
lastSyncedSpeed = energyState.getSpeed();
}
}
@Override
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
super.writeNBT(out, updatePacket);
if (mechanical!=null) {
NBTTagList mechParts = new NBTTagList();
for (MechMBPart part:mechanical) {
mechParts.appendTag(MechMBPart.toNBT(part));
}
out.setTag(PARTS, mechParts);
out.setDouble(SPEED, energyState.getSpeed());
}
}
@Override
public void readNBT(NBTTagCompound in, boolean updatePacket) {
super.readNBT(in, updatePacket);
if (in.hasKey(PARTS, Constants.NBT.TAG_LIST)) {
NBTTagList mechParts = in.getTagList(PARTS, Constants.NBT.TAG_COMPOUND);
MechMBPart[] mech = new MechMBPart[mechParts.tagCount()];
for (int i = 0; i < mechParts.tagCount(); i++) {
mech[i] = MechMBPart.fromNBT(mechParts.getCompoundTagAt(i), this);
}
setMechanical(mech, in.getDouble(SPEED));
}
rBB = null;
}
public void setMechanical(MechMBPart[] mech, double speed) {
mechanical = mech;
double weight = 0;
for (int i = 0; i < mech.length; i++) {
weight += mechanical[i].getWeight();
}
decay = Math.pow(DECAY_BASE, mechanical.length);//TODO init
energyState = new MechEnergy(weight, speed);
}
@Nonnull
@Override
protected BlockPos getOrigin() {
return pos;
}
@Override
public IBlockState getOriginalBlock() {
return null;
}
@Override
public void onSync(NBTTagCompound nbt) {
energyState.setSpeed(nbt.getDouble(SPEED));
}
private AxisAlignedBB rBB;
@Nonnull
@Override
public AxisAlignedBB getRenderBoundingBox() {
if (rBB==null) {
if (isLogicDummy()) {
rBB = new AxisAlignedBB(pos, pos);
} else {
rBB = new AxisAlignedBB(MiscUtils.offset(pos, facing, mirrored, -1, 0, -1),
MiscUtils.offset(pos, facing, mirrored, 2, mechanical.length, 2));
}
}
return rBB;
}
}

View file

@ -33,6 +33,7 @@ public enum BlockTypes_HVMultiblocks implements BlockIEBase.IBlockEnum {
return false;
}
@Override
public String getName() {
return name().toLowerCase();

View file

@ -76,6 +76,7 @@ import java.util.function.BiConsumer;
import static malte0811.industrialWires.blocks.hv.TileEntityMarx.FiringState.FIRE;
import static malte0811.industrialWires.util.MiscUtils.getOffset;
import static malte0811.industrialWires.util.MiscUtils.offset;
import static malte0811.industrialWires.util.NBTKeys.*;
import static net.minecraft.item.EnumDyeColor.*;
/**
@ -94,10 +95,6 @@ public class TileEntityMarx extends TileEntityIWMultiblock implements ITickable,
//Only relevant client-side.
private static final Set<TileEntityMarx> FIRING_GENERATORS = Collections.newSetFromMap(new WeakHashMap<>());
private static final String TYPE = "type";
private static final String STAGES = "stages";
private static final String HAS_CONN = "hasConn";
private static final String CAP_VOLTAGES = "capVoltages";
private double rcTimeConst;
private double timeFactor;
private double timeFactorBottom;

View file

@ -34,6 +34,7 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter;
import malte0811.industrialWires.blocks.hv.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.hv.TileEntityMarx;
import malte0811.industrialWires.client.gui.GuiPanelComponent;
@ -42,6 +43,7 @@ import malte0811.industrialWires.client.gui.GuiRSPanelConn;
import malte0811.industrialWires.client.gui.GuiRenameKey;
import malte0811.industrialWires.client.panelmodel.PanelModelLoader;
import malte0811.industrialWires.client.render.TileRenderJacobsLadder;
import malte0811.industrialWires.client.render.TileRenderMBConverter;
import malte0811.industrialWires.client.render.TileRenderMarx;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.crafting.IC2TRHelper;
@ -55,6 +57,7 @@ import net.minecraft.client.audio.MovingSound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
@ -118,6 +121,9 @@ public class ClientProxy extends CommonProxy {
ModelLoaderRegistry.registerLoader(new PanelModelLoader());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityJacobsLadder.class, new TileRenderJacobsLadder());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMarx.class, new TileRenderMarx());
TileRenderMBConverter tesr = new TileRenderMBConverter();
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMultiblockConverter.class, tesr);
((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(tesr);
}
@Override

View file

@ -11,7 +11,6 @@ import malte0811.industrialWires.client.gui.elements.GuiIntChooser;
import malte0811.industrialWires.containers.ContainerPanelComponent;
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemPanelComponent;
import malte0811.industrialWires.network.MessageItemSync;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiTextField;
@ -28,6 +27,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialWires.util.NBTKeys.*;
public class GuiPanelComponent extends GuiContainer {
private PanelComponent component;
private IConfigurableComponent confComp;
@ -266,41 +267,41 @@ public class GuiPanelComponent extends GuiContainer {
private void sync(int id, String value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setString(ItemPanelComponent.VALUE, value);
update.setInteger(TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ID, id);
update.setString(VALUE, value);
syncSingle(update);
}
private void sync(int id, boolean value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setBoolean(ItemPanelComponent.VALUE, value);
update.setInteger(TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ID, id);
update.setBoolean(VALUE, value);
syncSingle(update);
}
private void sync(int id, byte value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setByte(ItemPanelComponent.VALUE, value);
update.setInteger(TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ID, id);
update.setByte(VALUE, value);
syncSingle(update);
}
private void sync(int id, int value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setInteger(ItemPanelComponent.VALUE, value);
update.setInteger(TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ID, id);
update.setInteger(VALUE, value);
syncSingle(update);
}
private void sync(int id, float value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setFloat(ItemPanelComponent.VALUE, value);
update.setInteger(TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ID, id);
update.setFloat(VALUE, value);
syncSingle(update);
}
@ -308,37 +309,37 @@ public class GuiPanelComponent extends GuiContainer {
NBTTagList list = new NBTTagList();
for (int i = 0; i < stringTexts.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setString(ItemPanelComponent.VALUE, stringTexts.get(i).getText());
update.setInteger(TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ID, i);
update.setString(VALUE, stringTexts.get(i).getText());
list.appendTag(update);
}
for (int i = 0; i < boolButtons.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setBoolean(ItemPanelComponent.VALUE, boolButtons.get(i).state);
update.setInteger(TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ID, i);
update.setBoolean(VALUE, boolButtons.get(i).state);
list.appendTag(update);
}
for (int i = 0; i < rsChannelChoosers.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setByte(ItemPanelComponent.VALUE, rsChannelChoosers.get(i).getSelected());
update.setInteger(TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ID, i);
update.setByte(VALUE, rsChannelChoosers.get(i).getSelected());
list.appendTag(update);
}
for (int i = 0; i < intChoosers.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setInteger(ItemPanelComponent.VALUE, intChoosers.get(i).getValue());
update.setInteger(TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ID, i);
update.setInteger(VALUE, intChoosers.get(i).getValue());
list.appendTag(update);
}
for (int i = 0; i < floatSliders.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setFloat(ItemPanelComponent.VALUE, (float) floatSliders.get(i).getValue());
update.setInteger(TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ID, i);
update.setFloat(VALUE, (float) floatSliders.get(i).getValue());
list.appendTag(update);
}
sync(list);

View file

@ -0,0 +1,114 @@
/*
* 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.client.render;
import blusunrize.immersiveengineering.client.ClientUtils;
import malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter;
import malte0811.industrialWires.converter.MechMBPart;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import org.lwjgl.opengl.GL11;
import java.util.*;
import static malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter.TICK_ANGLE_PER_SPEED;
public class TileRenderMBConverter extends TileEntitySpecialRenderer<TileEntityMultiblockConverter> implements IResourceManagerReloadListener {
public static final Map<ResourceLocation, IBakedModel> BASE_MODELS = new HashMap<>();
@Override
public void render(TileEntityMultiblockConverter te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
if (BASE_MODELS.isEmpty()) {
for (MechMBPart type:MechMBPart.INSTANCES.values()) {
ResourceLocation loc = type.getRotatingBaseModel();
try {
IModel model = ModelLoaderRegistry.getModel(loc);
IBakedModel b = model.bake(model.getDefaultState(), DefaultVertexFormats.BLOCK, (rl)->Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(rl.toString()));
BASE_MODELS.put(loc, b);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
if (te.mechanical!=null) {
if (te.rotatingModel == null) {
te.rotatingModel = new ArrayList<>();
int offset = 0;
for (MechMBPart part : te.mechanical) {
List<BakedQuad> quadsForPart = part.getRotatingQuads();
if (offset != 0) {
for (BakedQuad b : quadsForPart) {
int[] data = Arrays.copyOf(b.getVertexData(), b.getVertexData().length);
int pos = 0;
for (VertexFormatElement ele : b.getFormat().getElements()) {
if (ele.getUsage() == VertexFormatElement.EnumUsage.POSITION) {
for (int i = 0;i<4;i++) {
data[i*b.getFormat().getIntegerSize()+pos + 2] = Float.floatToRawIntBits(
Float.intBitsToFloat(data[i*b.getFormat().getIntegerSize()+pos + 2]) + offset);
}
break;
}
pos += ele.getSize()/4;
}
BakedQuad translated = new BakedQuad(data, b.getTintIndex(), b.getFace(),
b.getSprite(), b.shouldApplyDiffuseLighting(), b.getFormat());
te.rotatingModel.add(translated);
}
} else {
te.rotatingModel.addAll(quadsForPart);
}
offset += part.getLength();
}
}
GlStateManager.enableBlend();
GlStateManager.disableCull();
GlStateManager.blendFunc(770, 771);
RenderHelper.disableStandardItemLighting();
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
GlStateManager.pushMatrix();
GlStateManager.translate(.5F + x, .5F + y, .5F + z);
GlStateManager.rotate(180-te.facing.getHorizontalAngle(), 0, 1, 0);
GlStateManager.rotate((float) (te.angle + te.energyState.getSpeed() * TICK_ANGLE_PER_SPEED * partialTicks),
0, 0, 1);
GlStateManager.translate(-.5, -.5, .5);
Tessellator tes = Tessellator.getInstance();
BufferBuilder bb = tes.getBuffer();
bb.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
ClientUtils.renderModelTESRFast(te.rotatingModel, bb, te.getWorld(), te.getPos());
tes.draw();
GlStateManager.popMatrix();
RenderHelper.enableStandardItemLighting();
}
}
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
BASE_MODELS.clear();
}
}

View file

@ -33,6 +33,8 @@ import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.List;
import static malte0811.industrialWires.util.NBTKeys.*;
public class CoveredToggleSwitch extends ToggleSwitch {
private int color = 0xff0000;
private SwitchState state = SwitchState.CLOSED;

View file

@ -39,6 +39,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import static malte0811.industrialWires.util.NBTKeys.*;
public class IndicatorLight extends PanelComponent implements IConfigurableComponent {
private int rsInputId;
private byte rsInputChannel;

View file

@ -40,6 +40,9 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import static malte0811.industrialWires.util.NBTKeys.COLOR;
import static malte0811.industrialWires.util.NBTKeys.TEXT;
public class Label extends PanelComponent implements IConfigurableComponent {
public static final ResourceLocation FONT = new ResourceLocation("minecraft", "textures/font/ascii.png");
private String text = "Test";

View file

@ -37,6 +37,8 @@ import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialWires.util.NBTKeys.*;
public class LightedButton extends PanelComponent implements IConfigurableComponent {
public int color = 0xFF0000;
public boolean active;

View file

@ -46,6 +46,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static malte0811.industrialWires.util.NBTKeys.*;
public class Lock extends PanelComponent implements IConfigurableComponent {
private final static Random rand = new Random();
@Nullable

View file

@ -22,7 +22,6 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.MiscUtils;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
@ -33,7 +32,6 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.Level;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -55,16 +53,6 @@ public abstract class PanelComponent {
}
public static final Map<String, Supplier<PanelComponent>> baseCreaters = new HashMap<>();
public final static String COLOR = "color";
public final static String RS_CHANNEL = "rsChannel";
public final static String RS_ID = "rsId";
public final static String HAS_SECOND_CHANNEL = "has2ndChannel";
public final static String RS_CHANNEL2 = "rsChannel2";
public final static String RS_ID2 = "rsId2";
public final static String TEXT = "text";
public static final String HORIZONTAL = "horizontal";
public static final String LENGTH = "length";
public static final String LATCHING = "latching";
static {
baseCreaters.put("lighted_button", LightedButton::new);

View file

@ -41,12 +41,12 @@ import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import static malte0811.industrialWires.util.NBTKeys.*;
public class PanelMeter extends PanelComponent implements IConfigurableComponent {
public static final String WIDE = "wide";
private int rsInputId, rsInputId2 = -1;
private byte rsInputChannel, rsInputChannel2;

View file

@ -26,7 +26,6 @@ import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.panelmodel.SmartLightingQuadIW;
import malte0811.industrialWires.controlpanel.PropertyComponents.PanelRenderProperties;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
@ -59,8 +58,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;
import static malte0811.industrialWires.controlpanel.PanelComponent.*;
import static malte0811.industrialWires.util.MiscUtils.discoverLocal;
import static malte0811.industrialWires.util.NBTKeys.*;
public final class PanelUtils {
public static TextureAtlasSprite PANEL_TEXTURE;
@ -320,8 +319,8 @@ public final class PanelUtils {
break;
case 8://Panel meter
addCommonInfo(data, list, false, true);
if (data.hasKey(PanelMeter.WIDE)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(PanelMeter.WIDE) ? "wide" : "narrow")));
if (data.hasKey(WIDE)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(WIDE) ? "wide" : "narrow")));
}
break;
}

View file

@ -38,6 +38,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static malte0811.industrialWires.util.NBTKeys.*;
public class Slider extends PanelComponent implements IConfigurableComponent {
private static final float WIDTH = .0625F;
private float length = .5F;

View file

@ -40,6 +40,9 @@ import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialWires.util.NBTKeys.RS_CHANNEL;
import static malte0811.industrialWires.util.NBTKeys.RS_ID;
public class ToggleSwitch extends PanelComponent implements IConfigurableComponent {
public boolean active;
public int rsOutputId;

View file

@ -43,6 +43,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static malte0811.industrialWires.util.NBTKeys.*;
public class Variac extends PanelComponent implements IConfigurableComponent {
private static final float SIZE = 3 / 16F;
private static final float innerSize = (float) (Math.sqrt(2) / 2 * SIZE);

View file

@ -0,0 +1,58 @@
/*
* 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.converter;
import javax.annotation.Nullable;
public interface IMBPartElectric {
/**
* If a section has more than one waveform (!=NONE) the generators are shorted (or worse), so it will:
* 1. Heat up the sources, possibly destroying them (TODO do I want to do that?)
* 2. Consume a lot of mechanical energy
*/
Waveform getProduced();
// This is EU
double getAvailableCurrent();
double requestCurrent(double total);
void consumeCurrent(double given);
enum Waveform {
NONE(null, 0, 0),
AC(true, 1, 2),
PULSED_DC(false, 2/Math.PI, 1),
MULTI_AC(true, 1, 4),//"4-phase" AC, magically transported by a single wire
MULTI_AC_RECT(true, 2*Math.sqrt(2)/Math.PI, 6),
DC(false, 1, 6),
SQUARE(true, Math.PI/4, 5);
@Nullable
public Boolean isEu;
public double efficiency;
private int dualId;
public Waveform dual;
Waveform(@Nullable Boolean eu, double efficiency, int dualId) {
isEu = eu;
this.efficiency = efficiency;
this.dualId = dualId;
}
public static void init() {
Waveform[] values = values();
for (Waveform f:values) {
f.dual = values[f.dualId];
}
}
}
}

View file

@ -0,0 +1,62 @@
/*
* 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.converter;
import blusunrize.immersiveengineering.common.util.Utils;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.oredict.OreDictionary;
public enum Material {
//TODO max speed
COPPER(8.96, 1e3),
ALUMINUM(2.7, 1e3),
LEAD(11.34, 1e3),
SILVER(10.49, 1e3),
NICKEL(8.908, 1e3),
GOLD(19.3, 1e3),
URANIUM(19.1, 1e3),// This is a bit silly. But why not.
CONSTANTAN(8.885, 1e3),
ELECTRUM((SILVER.density + GOLD.density) / 2, 1e3),
STEEL(7.874, 1e4),
IRON(7.874, 1e3);
public double density;
public double maxSpeed;
Material(double density, double maxSpeed) {
this.density = density;
this.maxSpeed = maxSpeed;
}
public boolean matchesBlock(ItemStack block, String prefix) {
int[] ids = OreDictionary.getOreIDs(block);
for (int i : ids) {
if (OreDictionary.getOreName(i).equalsIgnoreCase(prefix + oreName())) {
return true;
}
}
return false;
}
private String oreName() {
return name().substring(0, 1)+name().substring(1).toLowerCase();
}
public boolean matchesBlock(LocalSidedWorld w, BlockPos relative, String prefix) {
return Utils.isOreBlockAt(w.getWorld(), w.getRealPos(relative), prefix+oreName());
}
}

View file

@ -0,0 +1,53 @@
/*
* 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.converter;
public final class MechEnergy {
private double speed = 0;
public final double weight;
public MechEnergy(double weight, double speed) {
this.weight = weight;
this.speed = speed;
}
public double getEnergy() {
return .5*weight*speed*speed;
}
public double getSpeed() {
return speed;
}
public void addEnergy(double energy) {
double targetEnergy = getEnergy()+energy;
speed = Math.sqrt(2*targetEnergy/weight);
}
public void extractEnergy(double energy) {
double oldEnergy = getEnergy();
energy = Math.min(energy, oldEnergy);
speed = Math.sqrt(2*(oldEnergy-energy)/weight);
}
public void decaySpeed(double decay) {
speed *= decay;
}
//ONLY USE FOR SYNCING
public void setSpeed(double speed) {
this.speed = speed;
}
}

View file

@ -0,0 +1,145 @@
/*
* 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.converter;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter;
import malte0811.industrialWires.client.render.TileRenderMBConverter;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import static malte0811.industrialWires.blocks.converter.MechanicalMBBlockType.NO_MODEL;
import static malte0811.industrialWires.util.NBTKeys.TYPE;
public abstract class MechMBPart {
public static final Map<String, MechMBPart> INSTANCES = new HashMap<>();
private TileEntityMultiblockConverter master;
// These 3 are called once per tick in bulk in this order
public abstract void produceRotation(MechEnergy e);
public abstract double requestEnergy(MechEnergy e);
// This should do any misc ticking as well
public abstract void consumeRotation(double added);
public abstract double getWeight();
public abstract double getMaxSpeed();
public abstract void writeToNBT(NBTTagCompound out);
public abstract void readFromNBT(NBTTagCompound out);
@SideOnly(Side.CLIENT)
public List<BakedQuad> getRotatingQuads() {
return TileRenderMBConverter.BASE_MODELS.get(getRotatingBaseModel())
.getQuads(null, null, 123);
}
@SideOnly(Side.CLIENT)
public abstract ResourceLocation getRotatingBaseModel();
public abstract boolean canForm(LocalSidedWorld w);
public abstract short getFormPattern();
public abstract MechanicalMBBlockType getType();
private static final BiMap<String, Class<? extends MechMBPart>> REGISTRY = HashBiMap.create();
public static void init() {
IMBPartElectric.Waveform.init();
REGISTRY.put("flywheel", MechPartFlywheel.class);
REGISTRY.put("singleCoil", MechPartSingleCoil.class);
for (String key : REGISTRY.keySet()) {
cacheNewInstance(key);
}
}
public static void cacheNewInstance(String key) {
try {
MechMBPart instance = REGISTRY.get(key).newInstance();
INSTANCES.put(key, instance);
} catch (IllegalAccessException | InstantiationException e) {
throw new RuntimeException(e);
}
}
public static MechMBPart fromNBT(NBTTagCompound nbt, TileEntityMultiblockConverter master) {
String name = nbt.getString(TYPE);
Class<? extends MechMBPart> clazz = REGISTRY.get(name);
try {
MechMBPart ret = clazz.newInstance();
ret.readFromNBT(nbt);
ret.master = master;
return ret;
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("While creating mechanical MB part", e);
}
}
public static NBTTagCompound toNBT(MechMBPart part) {
Class<? extends MechMBPart> clazz = part.getClass();
String name = REGISTRY.inverse().get(clazz);
NBTTagCompound nbt = new NBTTagCompound();
part.writeToNBT(nbt);
nbt.setString(TYPE, name);
return nbt;
}
public static boolean isValidCenter(IBlockState state) {
return state.getBlock()== IEContent.blockMetalDecoration0&&
state.getValue(IEContent.blockMetalDecoration0.property)==BlockTypes_MetalDecoration0.LIGHT_ENGINEERING;
}
public void form(LocalSidedWorld w, Consumer<TileEntityMultiblockConverter> initializer) {
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 TileEntityMultiblockConverter) {
initializer.accept((TileEntityMultiblockConverter) te);
}
}
i++;
}
}
pos.release();
}
public int getLength() {
return 1;
}
}

View file

@ -0,0 +1,106 @@
/*
* 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.converter;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
public class MechPartFlywheel extends MechMBPart {
private static final double VOLUME = 7e6;//~7 cubic meters
private Material material;
//A flywheel simply adds mass (lots of mass!), it doesn't actively change speeds/energy
@Override
public void produceRotation(MechEnergy e) {}
@Override
public double requestEnergy(MechEnergy e) {
return 0;
}
@Override
public void consumeRotation(double added) {}
@Override
public double getWeight() {
return material.density*VOLUME;
}
@Override
public double getMaxSpeed() {
return Double.MAX_VALUE;//material.maxSpeed;
}
@Override
public void writeToNBT(NBTTagCompound out) {
out.setInteger("material", material.ordinal());
}
@Override
public void readFromNBT(NBTTagCompound out) {
material = Material.values()[out.getInteger("material")];
}
@Override
public ResourceLocation getRotatingBaseModel() {
return new ResourceLocation(IndustrialWires.MODID, "block/mech_mb/flywheel.obj");
}
@Override
public boolean canForm(LocalSidedWorld w) {
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain(-1, 1, 0);
try {
material = null;
for (Material m:Material.values()) {
if (m.matchesBlock(w, pos, "block")) {
material = m;
break;
}
}
if (material==null) {
return false;
}
for (int x = -1;x<=1;x++) {
for (int y = -1;y<=1;y++) {
pos.setPos(x, y, 0);
if ((x!=0||y!=0)&&!material.matchesBlock(w, pos, "block")) {
return false;
}
}
}
pos.setPos(0, 0, 0);
if (!isValidCenter(w.getBlockState(pos))) {
return false;
}
return true;
} finally {
pos.release();
}
}
@Override
public short getFormPattern() {
return 0b111_111_111;
}
@Override
public MechanicalMBBlockType getType() {
return MechanicalMBBlockType.FLYWHEEL;
}
}

View file

@ -0,0 +1,135 @@
/*
* 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.converter;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import java.util.function.Predicate;
//TODO electrical side of things. Currently a creative energy source
public class MechPartSingleCoil extends MechMBPart implements IMBPartElectric {
double inBuffer;
double outBuffer;
@Override
public Waveform getProduced() {
return Waveform.AC;
}
@Override
public double getAvailableCurrent() {
return 0;
}
@Override
public double requestCurrent(double total) {
return 0;
}
@Override
public void consumeCurrent(double given) {
}
@Override
public void produceRotation(MechEnergy e) {
e.addEnergy(1e11);
}
@Override
public double requestEnergy(MechEnergy e) {
return 0;
}
@Override
public void consumeRotation(double added) {
}
@Override
public double getWeight() {
return Material.IRON.density*1e6+Material.COPPER.density*1e5;
}
@Override
public double getMaxSpeed() {
return Double.MAX_VALUE;
}
@Override
public void writeToNBT(NBTTagCompound out) {
}
@Override
public void readFromNBT(NBTTagCompound out) {
}
@Override
public ResourceLocation getRotatingBaseModel() {
return new ResourceLocation(IndustrialWires.MODID, "block/mech_mb/single_coil.obj");
}
private static final Predicate<IBlockState> IS_COIL = (b)->
b.getBlock()== IEContent.blockMetalDecoration0&&
b.getValue(IEContent.blockMetalDecoration0.property)== BlockTypes_MetalDecoration0.COIL_LV;
@Override
public boolean canForm(LocalSidedWorld w) {
BlockPos.PooledMutableBlockPos pos = BlockPos.PooledMutableBlockPos.retain(0, 0, 0);
try {
if (!isValidCenter(w.getBlockState(pos))) {
return false;
}
pos.setPos(0, 1, 0);
if (!IS_COIL.test(w.getBlockState(pos))) {
return false;
}
pos.setPos(0, -1, 0);
if (!IS_COIL.test(w.getBlockState(pos))) {
return false;
}
int offset = 1;
for (int i = 0; i < 2; i++) {
for (int y = -1; y <= 1; y++) {
pos.setPos(offset, y, 0);
if (!w.isAir(pos)) {
return false;
}
}
}
return true;
} finally {
pos.release();//This will run after every return
}
}
@Override
public short getFormPattern() {
return 0b111_111_111;
}
@Override
public MechanicalMBBlockType getType() {
return MechanicalMBBlockType.COIL_1_PHASE;
}
}

View file

@ -0,0 +1,181 @@
/*
* 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.converter;
import blusunrize.immersiveengineering.api.MultiblockHandler;
import blusunrize.immersiveengineering.api.crafting.IngredientStack;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.converter.MechanicalMBBlockType;
import malte0811.industrialWires.blocks.converter.TileEntityMultiblockConverter;
import malte0811.industrialWires.util.LocalSidedWorld;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import static malte0811.industrialWires.blocks.converter.MechanicalMBBlockType.*;
public class MultiblockConverter implements MultiblockHandler.IMultiblock {
public static MultiblockConverter INSTANCE;
@Override
public String getUniqueName() {
return "iw:converter";
}
@Override
public boolean isBlockTrigger(IBlockState state) {
return MechMBPart.isValidCenter(state);
}
private boolean checkEnd(LocalSidedWorld w, BlockPos.PooledMutableBlockPos p) {
p.setPos(0, 0, 0);
if (!MechMBPart.isValidCenter(w.getBlockState(p))) {
return false;
}
p.setPos(0, -1, 0);
return MechMBPart.isValidCenter(w.getBlockState(p));
}
private void formEnd(LocalSidedWorld w, BlockPos.PooledMutableBlockPos p, MechanicalMBBlockType type,
BiConsumer<TileEntityMultiblockConverter, Boolean> init) {
p.setPos(0, 0, 0);
w.setBlockState(p, IndustrialWires.mechanicalMB.getStateFromMeta(type.ordinal()));
TileEntity te = w.getTileEntity(p);
if (te instanceof TileEntityMultiblockConverter) {
init.accept((TileEntityMultiblockConverter) te, true);
}
p.setPos(0, -1, 0);
w.setBlockState(p, IndustrialWires.mechanicalMB.getStateFromMeta(NO_MODEL.ordinal()));
te = w.getTileEntity(p);
if (te instanceof TileEntityMultiblockConverter) {
init.accept((TileEntityMultiblockConverter) te, false);
}
}
@Override
public boolean createStructure(World world, BlockPos pos, EnumFacing side, EntityPlayer player) {
boolean b = true;
BlockPos.PooledMutableBlockPos mutPos = BlockPos.PooledMutableBlockPos.retain();
Minecraft.getMinecraft().mouseHelper.ungrabMouseCursor();
try {
LocalSidedWorld w = new LocalSidedWorld(world, pos, side.getOpposite(), false);
if (!checkEnd(w, mutPos)) {
return false;
}
mirrorLoop:do {
b = !b;
w.setMirror(b);
boolean done = false;
List<MechMBPart> parts = new ArrayList<>();
int lastLength = 1;
double weight = 0;
while (!done) {
mutPos.setPos(0, 0, lastLength);
w.setOrigin(w.getRealPos(mutPos));
MechMBPart next = null;
for (String key:MechMBPart.INSTANCES.keySet()) {
MechMBPart it = MechMBPart.INSTANCES.get(key);
if (it.canForm(w)) {
next = it;
MechMBPart.cacheNewInstance(key);
break;
}
}
if (next!=null) {
parts.add(next);
lastLength = next.getLength();
weight += next.getWeight();
} else {
if (parts.size()>0&&checkEnd(w, mutPos)) {
done = true;
} else {
continue mirrorLoop;
}
}
}
double finalWeight = weight;
w.setOrigin(pos);
formEnd(w, mutPos, END, (te, master)->{
if (master) {
te.offset = BlockPos.ORIGIN;
te.setMechanical(parts.toArray(new MechMBPart[parts.size()]), 0);
te.energyState = new MechEnergy(finalWeight, 0);
} else {
te.offset = new BlockPos(0, -1, 0);
}
te.facing = side;
});
lastLength = 1;
Consumer<TileEntityMultiblockConverter> init = (te)-> {
te.offset = te.getPos().subtract(pos);
te.facing = side;
};
for (MechMBPart part:parts) {
mutPos.setPos(0, 0, lastLength);
w.setOrigin(w.getRealPos(mutPos));
part.form(w, init);
lastLength = part.getLength();
}
mutPos.setPos(0, 0, lastLength);
w.setOrigin(w.getRealPos(mutPos));
formEnd(w, mutPos, OTHER_END, (te, __)->init.accept(te));
break;
} while (!b);
return false;
} finally {
mutPos.release();
}
}
@Override
public ItemStack[][][] getStructureManual() {
return new ItemStack[0][][];
}
@Override
public IngredientStack[] getTotalMaterials() {
return new IngredientStack[0];
}
@Override
public boolean overwriteBlockRender(ItemStack stack, int iterator) {
return false;
}
@Override
public float getManualScale() {
return 1;
}
@Override
public boolean canRenderFormedStructure() {
return false;
}
@Override
public void renderFormedStructure() {
}
}

View file

@ -31,7 +31,7 @@ import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull;
import static malte0811.industrialWires.items.ItemKey.*;
import static malte0811.industrialWires.util.NBTKeys.*;
public class RecipeKeyRing extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {

View file

@ -31,16 +31,14 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import static malte0811.industrialWires.util.NBTKeys.*;
public class ItemKey extends Item implements INetGUIItem {
public static final String LOCK_ID = "lockId";
public static final String RING_KEYS = "ringkeys";
public static final String NAME = "name";
public static final String[] types = {"blank_key", "key", "key_ring"};
public static final String ITEM_NAME = "key";

View file

@ -52,14 +52,13 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import static malte0811.industrialWires.util.NBTKeys.*;
public class ItemPanelComponent extends Item implements INetGUIItem {
public static final String[] types = {
"lighted_button", "label", "indicator_light", "slider", "variac", "toggle_switch", "toggle_switch_covered",
"lock", "panel_meter"
};
public static final String TYPE = "type";
public static final String ID = "cfgId";
public static final String VALUE = "value";
public static final String NAME = "panel_component";
public ItemPanelComponent() {

View file

@ -0,0 +1,75 @@
/*
* 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.util;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class LocalSidedWorld {
private final World world;
private BlockPos origin;
private EnumFacing facing;
private boolean mirror;
public LocalSidedWorld(World world, BlockPos origin, EnumFacing facing, boolean mirror) {
this.world = world;
this.facing = facing;
this.mirror = mirror;
this.origin = origin;
}
public World getWorld() {
return world;
}
public void setFacing(EnumFacing facing) {
this.facing = facing;
}
public void setOrigin(BlockPos origin) {
this.origin = origin;
}
public void setMirror(boolean mirror) {
this.mirror = mirror;
}
public BlockPos getOrigin() {
return origin;
}
public IBlockState getBlockState(BlockPos pos) {
return world.getBlockState(getRealPos(pos));
}
public TileEntity getTileEntity(BlockPos pos) {
return world.getTileEntity(getRealPos(pos));
}
public boolean setBlockState(BlockPos pos, IBlockState setTo) {
return world.setBlockState(getRealPos(pos), setTo);
}
public boolean isAir(BlockPos pos) {
return world.isAirBlock(getRealPos(pos));
}
public BlockPos getRealPos(BlockPos relative) {
return MiscUtils.offset(origin, facing, mirror, relative);
}
}

View file

@ -92,6 +92,9 @@ public final class MiscUtils {
return ret;
}
public static BlockPos offset(BlockPos p, EnumFacing f, boolean mirror, BlockPos relative) {
return offset(p, f, mirror, relative.getX(), relative.getZ(), relative.getY());
}
/**
* @param mirror inverts right
*/

View file

@ -0,0 +1,56 @@
/*
* 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.util;
public final class NBTKeys {
private NBTKeys() {}
//General
public static final String ENERGY_TAG = "energy";
public static final String BUFFER_TAG = "buffer";
public static final String DIR_TAG = "dir";
public static final String TYPE = "type";
//Control panels
public static final String HEIGHT = "height";
public static final String ANGLE = "angle";
public static final String COLOR = "color";
public static final String RS_CHANNEL = "rsChannel";
public static final String RS_ID = "rsId";
public static final String HAS_SECOND_CHANNEL = "has2ndChannel";
public static final String RS_CHANNEL2 = "rsChannel2";
public static final String RS_ID2 = "rsId2";
public static final String TEXT = "text";
public static final String HORIZONTAL = "horizontal";
public static final String LENGTH = "length";
public static final String LATCHING = "latching";
public static final String WIDE = "wide";
public static final String LOCK_ID = "lockId";
public static final String RING_KEYS = "ringkeys";
public static final String NAME = "name";
public static final String ID = "cfgId";
public static final String VALUE = "value";
//HV
public static final String STAGES = "stages";
public static final String HAS_CONN = "hasConn";
public static final String CAP_VOLTAGES = "capVoltages";
//Mechanical
public static final String PARTS = "parts";
public static final String POS = "pos";
public static final String SPEED = "speed";
}

View file

@ -0,0 +1,45 @@
{
"forge_marker": 1,
"defaults": {
"transform": "forge:default-block",
"textures": {
},
"custom": {
"flip-v": true
},
"model": "builtin/generated"
},
"variants": {
"type": {
"no_model": {
},
"end": {
"model": "industrialwires:mech_mb/end.obj"
},
"other_end": {
"model": "industrialwires:mech_mb/end_other.obj"
},
"flywheel": {
},
"coil_1_phase": {
"model": "industrialwires:mech_mb/mag_ring.obj"
}
},
"facing":
{
"north": { "transform": {
"rotation": {"y": 0 }
}},
"south": { "transform": {
"rotation": {"y": 180 }
}},
"west": { "transform": {
"rotation": {"y": 90 }
}},
"east": { "transform": {
"rotation": {"y": -90 }
}}
}
}
}