Converted Tesla code to scala, with the exception of TeslaGrid as its deprecated
This commit is contained in:
parent
424b79f49d
commit
5fd4ae0669
7 changed files with 111 additions and 120 deletions
|
@ -1,23 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package resonantinduction.electrical.tesla;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface ITesla
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param transferEnergy - The energy amount in kilojoules.
|
|
||||||
* @param doTransfer - Actually transfer
|
|
||||||
* @return Energy actually transfered.
|
|
||||||
*/
|
|
||||||
public double teslaTransfer(double transferEnergy, boolean doTransfer);
|
|
||||||
|
|
||||||
public boolean canTeslaTransfer(TileEntity transferTile);
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package resonantinduction.electrical.tesla
|
||||||
|
|
||||||
|
import net.minecraft.tileentity.TileEntity
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Calclavia
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
abstract trait ITesla
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param transferEnergy - The energy amount in kilojoules.
|
||||||
|
* @param doTransfer - Actually transfer
|
||||||
|
* @return Energy actually transfered.
|
||||||
|
*/
|
||||||
|
def teslaTransfer(transferEnergy: Double, doTransfer: Boolean): Double
|
||||||
|
|
||||||
|
def canTeslaTransfer(transferTile: TileEntity): Boolean
|
||||||
|
}
|
|
@ -1,57 +0,0 @@
|
||||||
package resonantinduction.electrical.tesla;
|
|
||||||
|
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraftforge.client.model.AdvancedModelLoader;
|
|
||||||
import net.minecraftforge.client.model.IModelCustom;
|
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import resonantinduction.core.Reference;
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Calclavia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
public class RenderTesla extends TileEntitySpecialRenderer
|
|
||||||
{
|
|
||||||
public static final ResourceLocation TEXTURE_BOTTOM = new ResourceLocation(Reference.domain(), Reference.modelPath() + "tesla_bottom.png");
|
|
||||||
public static final ResourceLocation TEXTURE_MIDDLE = new ResourceLocation(Reference.domain(), Reference.modelPath() + "tesla_middle.png");
|
|
||||||
public static final ResourceLocation TEXTURE_TOP = new ResourceLocation(Reference.domain(), Reference.modelPath() + "tesla_top.png");
|
|
||||||
|
|
||||||
public static final IModelCustom MODEL_BOTTOM = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "teslaBottom.tcn"));
|
|
||||||
public static final IModelCustom MODEL_MIDDLE = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "teslaMiddle.tcn"));
|
|
||||||
public static final IModelCustom MODEL_TOP = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "teslaTop.tcn"));
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
|
|
||||||
{
|
|
||||||
GL11.glPushMatrix();
|
|
||||||
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
|
|
||||||
|
|
||||||
int meta = t.getBlockType() != null ? t.getBlockMetadata() : 0;
|
|
||||||
|
|
||||||
switch (meta)
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
bindTexture(TEXTURE_BOTTOM);
|
|
||||||
MODEL_BOTTOM.renderAll();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
bindTexture(TEXTURE_MIDDLE);
|
|
||||||
MODEL_MIDDLE.renderAll();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
bindTexture(TEXTURE_TOP);
|
|
||||||
MODEL_TOP.renderAll();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
GL11.glPopMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package resonantinduction.electrical.tesla
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
|
||||||
|
import net.minecraft.tileentity.TileEntity
|
||||||
|
import net.minecraft.util.ResourceLocation
|
||||||
|
import net.minecraftforge.client.model.AdvancedModelLoader
|
||||||
|
import net.minecraftforge.client.model.IModelCustom
|
||||||
|
import org.lwjgl.opengl.GL11
|
||||||
|
import resonantinduction.core.Reference
|
||||||
|
import cpw.mods.fml.relauncher.Side
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Calclavia
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SideOnly(Side.CLIENT) object RenderTesla
|
||||||
|
{
|
||||||
|
final val TEXTURE_BOTTOM: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "tesla_bottom.png")
|
||||||
|
final val TEXTURE_MIDDLE: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "tesla_middle.png")
|
||||||
|
final val TEXTURE_TOP: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "tesla_top.png")
|
||||||
|
final val MODEL_BOTTOM: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "teslaBottom.tcn"))
|
||||||
|
final val MODEL_MIDDLE: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "teslaMiddle.tcn"))
|
||||||
|
final val MODEL_TOP: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "teslaTop.tcn"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
class RenderTesla extends TileEntitySpecialRenderer
|
||||||
|
{
|
||||||
|
def renderTileEntityAt(t: TileEntity, x: Double, y: Double, z: Double, f: Float)
|
||||||
|
{
|
||||||
|
GL11.glPushMatrix
|
||||||
|
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
|
||||||
|
val meta: Int = if (t.getBlockType != null) t.getBlockMetadata else 0
|
||||||
|
|
||||||
|
if (meta == 1)
|
||||||
|
{
|
||||||
|
bindTexture(RenderTesla.TEXTURE_MIDDLE)
|
||||||
|
RenderTesla.MODEL_MIDDLE.renderAll
|
||||||
|
}
|
||||||
|
else if (meta == 2)
|
||||||
|
{
|
||||||
|
bindTexture(RenderTesla.TEXTURE_TOP)
|
||||||
|
RenderTesla.MODEL_TOP.renderAll
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bindTexture(RenderTesla.TEXTURE_BOTTOM)
|
||||||
|
RenderTesla.MODEL_BOTTOM.renderAll
|
||||||
|
}
|
||||||
|
GL11.glPopMatrix
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ import resonant.api.mffs.fortron.IServerThread;
|
||||||
* @author Calclavia
|
* @author Calclavia
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Deprecated // TODO "Should be replaced with a shared frequency grid" - from Darkguardsman
|
||||||
public class TeslaGrid
|
public class TeslaGrid
|
||||||
{
|
{
|
||||||
private static final TeslaGrid INSTANCE_CLIENT = new TeslaGrid();
|
private static final TeslaGrid INSTANCE_CLIENT = new TeslaGrid();
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package resonantinduction.electrical.transformer;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.MathHelper;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import resonantinduction.core.ResonantPartFactory$;
|
|
||||||
import resonantinduction.core.prefab.part.IHighlight;
|
|
||||||
import codechicken.lib.vec.BlockCoord;
|
|
||||||
import codechicken.lib.vec.Vector3;
|
|
||||||
import codechicken.microblock.FacePlacementGrid$;
|
|
||||||
import codechicken.multipart.JItemMultiPart;
|
|
||||||
import codechicken.multipart.MultiPartRegistry;
|
|
||||||
import codechicken.multipart.TMultiPart;
|
|
||||||
import resonantinduction.electrical.multimeter.PartMultimeter;
|
|
||||||
|
|
||||||
public class ItemElectricTransformer extends JItemMultiPart implements IHighlight
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public TMultiPart newPart(ItemStack itemStack, EntityPlayer player, World world, BlockCoord pos, int side, Vector3 hit)
|
|
||||||
{
|
|
||||||
side = FacePlacementGrid$.MODULE$.getHitSlot(hit, side);
|
|
||||||
PartElectricTransformer part = ResonantPartFactory$.MODULE$.create(PartElectricTransformer.class);
|
|
||||||
|
|
||||||
if (part != null)
|
|
||||||
{
|
|
||||||
int l = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
|
|
||||||
int facing = l == 0 ? 2 : (l == 1 ? 5 : (l == 2 ? 3 : (l == 3 ? 4 : 0)));
|
|
||||||
part.preparePlacement(side, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
return part;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHighlightType()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package resonantinduction.electrical.transformer
|
||||||
|
|
||||||
|
import codechicken.lib.vec.{BlockCoord, Vector3}
|
||||||
|
import codechicken.microblock.FacePlacementGrid
|
||||||
|
import codechicken.multipart.{JItemMultiPart, TMultiPart}
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
|
import net.minecraft.item.ItemStack
|
||||||
|
import net.minecraft.util.MathHelper
|
||||||
|
import net.minecraft.world.World
|
||||||
|
import resonantinduction.core.ResonantPartFactory
|
||||||
|
import resonantinduction.core.prefab.part.IHighlight
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Item for Electric Transformer that handles block/part placement
|
||||||
|
*/
|
||||||
|
class ItemElectricTransformer extends JItemMultiPart with IHighlight
|
||||||
|
{
|
||||||
|
override def newPart(itemStack: ItemStack, player: EntityPlayer, world: World, pos: BlockCoord, s: Int, hit: Vector3): TMultiPart =
|
||||||
|
{
|
||||||
|
val side: Int = FacePlacementGrid.getHitSlot(hit, s)
|
||||||
|
val part: PartElectricTransformer = ResonantPartFactory.create(classOf[PartElectricTransformer])
|
||||||
|
if (part != null)
|
||||||
|
{
|
||||||
|
val l: Int = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3
|
||||||
|
val facing: Int = if (l == 0) 2 else (if (l == 1) 5 else (if (l == 2) 3 else (if (l == 3) 4 else 0)))
|
||||||
|
part.preparePlacement(side, facing)
|
||||||
|
}
|
||||||
|
return part
|
||||||
|
}
|
||||||
|
|
||||||
|
override def getHighlightType: Int =
|
||||||
|
{
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue