mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-19 03:49:05 +00:00
refactor: port microblock base to Java
This commit is contained in:
1 parent
30925fbddd
commit
fa675676ae
10 files changed
+353
-217
No files matched your search
@@ -1145,3 +1145,13 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
- A clean build passes all 241 plain-JVM tests and the Java 8 Forge server passes all 103 tests. The clean reference and
|
||||
port jars contain the same three runtime types and every callable public descriptor matches. `microblock/Microblock.scala`
|
||||
is the next deliberately high-risk target.
|
||||
- Characterized the `Microblock` base, its default-argument companion and all three mixin traits against untouched
|
||||
Scala. Three plain-JVM cases freeze the eight retained type surfaces, fields, constructor/default, signed shape
|
||||
packing, material delegation, item conversion, description/update bytes and core NBT.
|
||||
- Ported `Microblock` and `Microblock$` directly to Java while moving `MicroblockClient`, `CommonMicroblock` and
|
||||
`CommonMicroblockClient` unchanged to `MicroblockTraits.scala`. Keeping those load-bearing Scala traits avoids a
|
||||
Java single-inheritance workaround and preserves the existing ProjectRed generator path. Three remaining Scala
|
||||
assignments now call the same public field setters explicitly.
|
||||
- A clean build passes all 244 plain-JVM tests and the Java 8 Forge server passes all 103 tests, including generated
|
||||
face/hollow parts and the external Scala microblock trait fixture. All eight retained public surfaces match the
|
||||
reference; only two private Scala iteration closures disappear. `microblock/FaceMicroblock.scala` is next.
|
||||
@@ -2702,3 +2702,50 @@ No runtime class is added or removed; both clean jars contain the same three sup
|
||||
names/descriptors and retained field/annotation shapes.
|
||||
- The real constructor cannot be initialized under the plain-JVM application class loader; exact generator calls are
|
||||
therefore frozen at the bytecode boundary and exercised end to end by the Forge suite.
|
||||
|
||||
## 2026-09-01 — Microblock base Java port
|
||||
|
||||
The shared abstract microblock base and its generated default-argument companion are now Java. The three mixin traits
|
||||
from the same source unit remain Scala in `MicroblockTraits.scala`; translating them would require either changing
|
||||
their multiple-inheritance shape or widening the mixin generator, neither of which is needed to port the base.
|
||||
|
||||
### Observable behavior
|
||||
|
||||
No known gameplay divergence. Material and shape state, signed-byte shape packing, cuboid routing, type/strength/light/
|
||||
transparency/resistance delegation, drop denominations, pick-item preference, description and update bytes, tile
|
||||
notification order, and `shape`/`material` NBT remain unchanged.
|
||||
|
||||
`getDrops()` now returns a directly populated `ArrayList` instead of the Java view of a Scala `ListBuffer`. Both are
|
||||
mutable Java `List` implementations with the same ordered contents; no audited consumer depends on the concrete list
|
||||
class. Direct `4, 2, 1` loops also replace Scala collection traversal and `pickItem`'s non-local-return exception.
|
||||
|
||||
### ABI and reflection compatibility
|
||||
|
||||
`Microblock` remains a public abstract subclass of `TMultiPart` implementing `TCuboidPart`, with exactly one public
|
||||
`(int)` constructor, the same private mutable `material: int` and `shape: byte` fields, and every callable public name
|
||||
and descriptor retained. `Microblock$`, `MODULE$`, the constructor-default method and its static forwarder also remain.
|
||||
GuideNH's reflected `microClass()`, `material()` and `shape()` members and Schematica's `Microblock` type identity are
|
||||
therefore unchanged.
|
||||
|
||||
`MicroblockClient`, `CommonMicroblock`, `CommonMicroblockClient` and their three `$class` helpers remain Scala and
|
||||
retain their exact interface hierarchy and public descriptors. The three remaining Scala source assignments in the
|
||||
corner/edge units now name `shape_$eq(byte)` explicitly because Java classfiles do not carry Scala source-property
|
||||
metadata; the emitted call and runtime behavior are the same.
|
||||
|
||||
Accepted classfile-only differences are removed Scala signature/marker attributes from `Microblock`, Java's ordinary
|
||||
companion class-initializer flag, and the traits' updated source-file marker.
|
||||
|
||||
### Compiler artifacts
|
||||
|
||||
`Microblock$$anonfun$getDrops$1` and `Microblock$$anonfun$pickItem$1` disappear. The direct Java loops need neither
|
||||
private Scala closure; the downstream inventory contains no reference to them. The other eight supported runtime
|
||||
types are unchanged.
|
||||
|
||||
### Validation
|
||||
|
||||
- `MicroblockCharacterizationTest`: 3 plain-JVM tests, unchanged from the Scala baseline.
|
||||
- Clean complete plain-JVM suite: 244 tests, 0 failures, 0 errors.
|
||||
- Java 8 Forge dedicated-server suite: 103 tests, 0 failures, 0 errors, including generated face/hollow parts and a
|
||||
separately compiled external Scala microblock trait.
|
||||
- Raw `javap` comparison confirms identical callable public names/descriptors for `Microblock`, `Microblock$`, all
|
||||
three traits and all three `$class` helpers; the retained class inventory is otherwise exact.
|
||||
@@ -12,8 +12,8 @@ what breaks, and what is left. The other documents hold the reasoning.
|
||||
| `JAVA_MIGRATION_MANUAL_CHECKS.md` | What no automated test can cover, and must be checked by hand in a client |
|
||||
| `JAVA_MIGRATION_PROFILE.md` | The focused baseline, first measured result, findings, and exact rerun command |
|
||||
|
||||
Branch: `algent/java`. Base: `master`. 134 commits including the API-cleanup plan and separate characterization and
|
||||
port commits through `MicroblockClass`.
|
||||
Branch: `algent/java`. Base: `master`. 136 commits including the API-cleanup plan and separate characterization and
|
||||
port commits through the `Microblock` base.
|
||||
|
||||
## The one rule that matters
|
||||
|
||||
@@ -67,7 +67,7 @@ awk -F'"' '/<testsuite /{t+=$4;f+=$8;e+=$10} END{print "tests="t" failures="f" e
|
||||
grep -o 'tests="[0-9]*" skipped="[0-9]*" failures="[0-9]*" errors="[0-9]*"' run/server/junit-out/TEST-*.xml
|
||||
```
|
||||
|
||||
Current baseline: **241 plain-JVM tests and 103 Java 8 Forge dedicated-server tests passing.** The ignored local server
|
||||
Current baseline: **244 plain-JVM tests and 103 Java 8 Forge dedicated-server tests passing.** The ignored local server
|
||||
EULA is accepted in this checkout. GitHub Actions runs the same self-validating Forge suite in a dependent job after
|
||||
the shared GTNH build; keep both jobs required.
|
||||
|
||||
@@ -270,7 +270,7 @@ across the port. It is also where the two shim constraints in the gotchas list w
|
||||
`rayTraceAll`'s index production is now characterized, closing the gap the read-path cleanup left: the index written
|
||||
into `ExtendedMOP.data` is what `reduceMOP` hands back to every click, activate, harvest and pick block.
|
||||
|
||||
165 Java files, 16 Scala files, ~3,234 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
167 Java files, 16 Scala files, ~3,139 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
|
||||
## What is left, and in what order
|
||||
|
||||
@@ -484,9 +484,15 @@ Forge suite exercises eager base-trait registration, lazy client-trait avoidance
|
||||
built-in factories and generated parts. The three runtime class names and all callable public descriptors match the
|
||||
reference, including the GuideNH-pinned `MicroblockGenerator$.create(MicroblockClass, int, boolean)` boundary.
|
||||
|
||||
**High.** `Microblock.scala` is next. It is the shared transformed base for the face, hollow, edge and corner hierarchy,
|
||||
so freeze the exact trait/class hierarchy, state fields and accessors, NBT/shape behavior, generated interfaces and
|
||||
Scala-trait consumer paths before translating it. Do not combine it with a shape subclass or generator change.
|
||||
The `Microblock` abstract base and `Microblock$` are now Java. Three plain-JVM cases freeze all eight retained base,
|
||||
companion, trait and `$class` surfaces plus state, signed shape packing, material behavior, item conversion, core NBT
|
||||
and packet/update bytes. `MicroblockClient`, `CommonMicroblock` and `CommonMicroblockClient` deliberately remain Scala
|
||||
in `MicroblockTraits.scala`: this preserves their multiple-inheritance ABI and ProjectRed's existing Scala-trait
|
||||
generator path without an ASM change. The Forge suite still generates built-in parts and the external Scala fixture.
|
||||
|
||||
**Medium.** `FaceMicroblock.scala` is next. Apply the same narrow split: characterize its factory/facade, placement
|
||||
singleton, bounds table and both traits, then port the concrete/singleton code while retaining generated traits unless
|
||||
an exact Java representation is proven first. Do not combine it with another shape family.
|
||||
|
||||
**Phase 5 is complete.** There are no Scala files left in `multipart/scalatraits/`. The client pair required the first
|
||||
narrow generator relaxation: Java-trait parent linearization, explicit field-accessor recognition, and exclusion of
|
||||
@@ -515,8 +521,9 @@ complete.
|
||||
jar instead sees concrete Java mixin inputs and can emit class/field opcodes that are invalid after Forge rewrites
|
||||
them to interfaces. Provide a transformed compile stub or downstream source guidance before claiming
|
||||
source-compatible rebuilds.
|
||||
- Microblock-specific NBT still needs characterization immediately before that subsystem changes. The registry
|
||||
handshake packet's channel, type, count and ordered material names are now frozen.
|
||||
- Core microblock `shape`/`material` NBT plus description and one-byte shape updates are frozen. Characterize any
|
||||
shape-specific state or packet behavior immediately before changing its subclass. The registry handshake packet's
|
||||
channel, type, count and ordered material names are also frozen.
|
||||
- `TileMultipart` still republishes an immutable Scala `Seq` on every mutation. Its internal read paths now avoid Java
|
||||
list copies and wrappers; the remaining mutable snapshots at add/remove sites are intentional.
|
||||
- The focused synthetic redstone allocation is resolved (80.5 B to 0.0 B per three-query iteration). A representative
|
||||
|
||||
@@ -50,12 +50,12 @@ below its table.
|
||||
| [ ] | Load the pack with ProjRed installed and place illumar lamp microblocks | The lamps generate, render and light correctly | `MicroblockGenerator.registerTrait` Scala trait path |
|
||||
| [ ] | Place and break OpenComputers, ProjectBlue and AE2 parts | No `NoSuchMethodError` or `AbstractMethodError` in the log | retained `$class` bridges |
|
||||
| [ ] | Load and render a schematic containing an ordered mixed multipart tile | Every part appears in the preview in the saved order; the integration does not silently disable itself | Schematica private registry-map reflection, `MicroblockClass.create`, and tile NBT reconstruction |
|
||||
| [ ] | Open a GuideNH scene containing a multipart tile and export its part/material data | The preview, material data and part statistics are complete | companion reflection, `MicroblockGenerator$.create`, `partList_$eq`, and `BlockMicroMaterial` mixin fields |
|
||||
| [ ] | Open a GuideNH scene containing a multipart tile and export its part/material data | The preview, material data and part statistics are complete | companion reflection, `MicroblockGenerator$.create`, `Microblock.microClass/material/shape`, `partList_$eq`, and `BlockMicroMaterial` mixin fields |
|
||||
| [ ] | Place FMP buttons on every supported face with Et Futurum loaded | Button orientation matches the fixed vanilla behavior | reflected mutable `ButtonPart` side/meta arrays |
|
||||
| [ ] | Toggle an OpenComputers print that shares a block with another slotted part | Its slots are rebuilt without losing, hiding or disconnecting either part | external mutation of `TSlottedTile.v_partMap` plus `bindPart` |
|
||||
| [ ] | Move the same composite tile once through ForgeRelocationFMP and once through MatterManipulator | Coordinates, part-to-tile references, generated interfaces and rendering remain correct after `onMoved` | live multipart move lifecycle |
|
||||
| [ ] | Inspect a mixed multipart tile with Waila | Providers receive every saved part ID and show the expected part data | reflected block identity and tile NBT `parts`/`id` layout |
|
||||
| [ ] | Load a world saved before the port | All microblocks and covers keep their material and shape | `MicroMaterialRegistry` id map |
|
||||
| [ ] | Load a world saved before the port | All microblocks and covers keep their material and shape | `Microblock` shape/material NBT and `MicroMaterialRegistry` id map |
|
||||
| [ ] | Join a server whose material set differs from the client | The client is disconnected with the missing material list, not a crash | `readIDMap` |
|
||||
| [ ] | Join a server whose multipart type set differs from the client | The client is disconnected with the ordered missing-part list, not a crash | `MultipartCPH.handlePartRegistration` |
|
||||
|
||||
@@ -63,5 +63,5 @@ below its table.
|
||||
|
||||
- [ ] A focused pre-optimization CPU/allocation baseline now exists in `JAVA_MIGRATION_PROFILE.md`. A representative
|
||||
full-pack capture and the matching post-optimization comparison still need to be performed.
|
||||
- [ ] Microblock-specific NBT and packet payloads. The compact core tile/part NBT and logical chunk-description fixtures
|
||||
are complete.
|
||||
- [ ] Shape-specific microblock NBT and packet payloads. Core `Microblock` shape/material NBT, description bytes and
|
||||
one-byte shape updates are complete, along with compact core tile/part NBT and logical chunk-description fixtures.
|
||||
@@ -41,8 +41,9 @@ object CornerMicroClass extends CommonMicroClass {
|
||||
}
|
||||
|
||||
trait CornerMicroblock extends CommonMicroblock {
|
||||
override def setShape(size: Int, slot: Int) = shape =
|
||||
override def setShape(size: Int, slot: Int) = shape_$eq(
|
||||
(size << 4 | (slot - 7)).toByte
|
||||
)
|
||||
|
||||
def microClass = CornerMicroClass
|
||||
|
||||
|
||||
@@ -48,7 +48,9 @@ object EdgePlacement extends PlacementProperties {
|
||||
if (hpart.getType == PostMicroClass.getName) {
|
||||
val mpart = hpart.asInstanceOf[Microblock]
|
||||
if (mpart.material == pmt.material && mpart.getSize + pmt.size < 8) {
|
||||
part.shape = ((mpart.getSize + pmt.size) << 4 | mpart.getShape).toByte
|
||||
part.shape_$eq(
|
||||
((mpart.getSize + pmt.size) << 4 | mpart.getShape).toByte
|
||||
)
|
||||
return pmt.expand(mpart, part)
|
||||
}
|
||||
}
|
||||
@@ -94,8 +96,9 @@ object EdgeMicroClass extends CommonMicroClass {
|
||||
}
|
||||
|
||||
trait EdgeMicroblock extends CommonMicroblock with TEdgePart {
|
||||
override def setShape(size: Int, slot: Int) = shape =
|
||||
override def setShape(size: Int, slot: Int) = shape_$eq(
|
||||
(size << 4 | (slot - 15)).toByte
|
||||
)
|
||||
|
||||
def microClass = EdgeMicroClass
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package codechicken.microblock;
|
||||
|
||||
public final class Microblock$ {
|
||||
|
||||
public static final Microblock$ MODULE$ = new Microblock$();
|
||||
|
||||
private Microblock$() {}
|
||||
|
||||
public int $lessinit$greater$default$1() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package codechicken.microblock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
import codechicken.lib.data.MCDataOutput;
|
||||
import codechicken.lib.raytracer.IndexedCuboid6;
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.multipart.JCuboidPart;
|
||||
import codechicken.multipart.TCuboidPart;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
|
||||
public abstract class Microblock extends TMultiPart implements TCuboidPart {
|
||||
|
||||
private int material;
|
||||
private byte shape;
|
||||
|
||||
public static int $lessinit$greater$default$1() {
|
||||
return Microblock$.MODULE$.$lessinit$greater$default$1();
|
||||
}
|
||||
|
||||
public Microblock(int material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public int material() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public void material_$eq(int value) {
|
||||
material = value;
|
||||
}
|
||||
|
||||
public byte shape() {
|
||||
return shape;
|
||||
}
|
||||
|
||||
public void shape_$eq(byte value) {
|
||||
shape = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<IndexedCuboid6> getSubParts() {
|
||||
return JCuboidPart.subParts(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Cuboid6> getCollisionBoxes() {
|
||||
return JCuboidPart.collisionBoxes(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBreaking(RenderBlocks renderBlocks) {
|
||||
JCuboidPart.renderBreaking(this, renderBlocks);
|
||||
}
|
||||
|
||||
public abstract MicroblockClass microClass();
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return microClass().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getStrength(MovingObjectPosition hit, EntityPlayer player) {
|
||||
MicroMaterialRegistry.IMicroMaterial microMaterial = getIMaterial();
|
||||
return microMaterial == null ? super.getStrength(hit, player) : microMaterial.getStrength(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesTick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return shape >> 4;
|
||||
}
|
||||
|
||||
public int getShape() {
|
||||
return shape & 0xF;
|
||||
}
|
||||
|
||||
public void setShape(int size, int slot) {
|
||||
shape = (byte) (size << 4 | slot);
|
||||
}
|
||||
|
||||
public int getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
||||
public MicroMaterialRegistry.IMicroMaterial getIMaterial() {
|
||||
return MicroMaterialRegistry.getMaterial(material);
|
||||
}
|
||||
|
||||
public abstract int itemClassID();
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops() {
|
||||
int remaining = getSize();
|
||||
List<ItemStack> items = new ArrayList<>(3);
|
||||
for (int size = 4; size > 0; size /= 2) {
|
||||
int amount = remaining / size;
|
||||
remaining -= amount * size;
|
||||
if (amount > 0) {
|
||||
items.add(
|
||||
ItemMicroPart.create(
|
||||
amount,
|
||||
size | itemClassID() << 8,
|
||||
MicroMaterialRegistry.materialName(material)));
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack pickItem(MovingObjectPosition hit) {
|
||||
int size = getSize();
|
||||
for (int itemSize = 4; itemSize > 0; itemSize /= 2) {
|
||||
if (size % itemSize == 0 && size / itemSize >= 1) {
|
||||
return ItemMicroPart
|
||||
.create(itemSize | itemClassID() << 8, MicroMaterialRegistry.materialName(material));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet) {
|
||||
MicroMaterialRegistry.writeMaterialID(packet, material);
|
||||
packet.writeByte(shape);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readDesc(MCDataInput packet) {
|
||||
shape = packet.readByte();
|
||||
}
|
||||
|
||||
public void sendShapeUpdate() {
|
||||
getWriteStream().writeByte(shape);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(MCDataInput packet) {
|
||||
super.read(packet);
|
||||
tile().notifyPartChange(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound tag) {
|
||||
tag.setByte("shape", shape);
|
||||
tag.setString("material", MicroMaterialRegistry.materialName(material));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound tag) {
|
||||
shape = tag.getByte("shape");
|
||||
material = MicroMaterialRegistry.materialID(tag.getString("material"));
|
||||
}
|
||||
|
||||
public boolean isTransparent() {
|
||||
return getIMaterial().isTransparent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue() {
|
||||
return getIMaterial().getLightValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float explosionResistance(Entity entity) {
|
||||
return getIMaterial().explosionResistance(entity) * microClass().getResistanceFactor();
|
||||
}
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
package codechicken.microblock
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import codechicken.lib.lighting.LightMatrix
|
||||
import codechicken.microblock.MicroMaterialRegistry._
|
||||
import codechicken.lib.vec.BlockCoord
|
||||
import org.lwjgl.opengl.GL11
|
||||
import codechicken.lib.render.CCRenderState
|
||||
import net.minecraft.world.World
|
||||
import codechicken.lib.vec.Cuboid6
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.multipart.TIconHitEffects
|
||||
import codechicken.multipart.IconHitEffects
|
||||
import net.minecraft.client.particle.EffectRenderer
|
||||
import net.minecraft.util.IIcon
|
||||
import net.minecraft.block.Block
|
||||
import codechicken.multipart.TCuboidPart
|
||||
import codechicken.multipart.JCuboidPart
|
||||
import codechicken.multipart.TMultiPart
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import codechicken.multipart.JPartialOcclusion
|
||||
import codechicken.lib.render.Vertex5
|
||||
import net.minecraft.item.ItemStack
|
||||
import scala.collection.mutable.ListBuffer
|
||||
import codechicken.lib.data.MCDataOutput
|
||||
import codechicken.lib.data.MCDataInput
|
||||
import codechicken.lib.render.RenderUtils
|
||||
import codechicken.lib.render.IFaceRenderer
|
||||
import codechicken.multipart.TSlottedPart
|
||||
import scala.collection.JavaConversions._
|
||||
import codechicken.lib.render.TextureUtils
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.init.Blocks
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import codechicken.lib.render.BlockRenderer.BlockFace
|
||||
|
||||
abstract class Microblock(var material: Int = 0)
|
||||
extends TMultiPart
|
||||
with TCuboidPart {
|
||||
var shape: Byte = 0
|
||||
|
||||
// TCuboidPart is a Java interface, so these must be declared explicitly or TMultiPart's empty versions win.
|
||||
override def getSubParts = JCuboidPart.subParts(this)
|
||||
|
||||
override def getCollisionBoxes = JCuboidPart.collisionBoxes(this)
|
||||
|
||||
override def drawBreaking(renderBlocks: RenderBlocks) =
|
||||
JCuboidPart.renderBreaking(this, renderBlocks)
|
||||
|
||||
def microClass: MicroblockClass
|
||||
|
||||
def getType = microClass.getName
|
||||
|
||||
override def getStrength(hit: MovingObjectPosition, player: EntityPlayer) =
|
||||
getIMaterial match {
|
||||
case null => super.getStrength(hit, player)
|
||||
case mat => mat.getStrength(player)
|
||||
}
|
||||
|
||||
override def doesTick = false
|
||||
|
||||
def getSize = shape >> 4
|
||||
|
||||
def getShape = shape & 0xf
|
||||
|
||||
def setShape(size: Int, slot: Int) = shape = (size << 4 | slot).toByte
|
||||
|
||||
def getMaterial = material
|
||||
|
||||
def getIMaterial = MicroMaterialRegistry.getMaterial(material)
|
||||
|
||||
def itemClassID: Int
|
||||
|
||||
override def getDrops = {
|
||||
var size = getSize
|
||||
val items = ListBuffer[ItemStack]()
|
||||
for (s <- Seq(4, 2, 1)) {
|
||||
val m = size / s
|
||||
size -= m * s
|
||||
if (m > 0)
|
||||
items += ItemMicroPart.create(
|
||||
m,
|
||||
s | itemClassID << 8,
|
||||
MicroMaterialRegistry.materialName(material)
|
||||
)
|
||||
}
|
||||
items
|
||||
}
|
||||
|
||||
override def pickItem(hit: MovingObjectPosition): ItemStack = {
|
||||
val size = getSize
|
||||
for (s <- Seq(4, 2, 1))
|
||||
if (size % s == 0 && size / s >= 1)
|
||||
return ItemMicroPart.create(
|
||||
s | itemClassID << 8,
|
||||
MicroMaterialRegistry.materialName(material)
|
||||
)
|
||||
|
||||
return null // unreachable
|
||||
}
|
||||
|
||||
override def writeDesc(packet: MCDataOutput) {
|
||||
writeMaterialID(packet, material)
|
||||
packet.writeByte(shape)
|
||||
}
|
||||
|
||||
override def readDesc(packet: MCDataInput) {
|
||||
shape = packet.readByte
|
||||
}
|
||||
|
||||
def sendShapeUpdate() {
|
||||
getWriteStream.writeByte(shape)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput) {
|
||||
super.read(packet)
|
||||
tile.notifyPartChange(this)
|
||||
}
|
||||
|
||||
override def save(tag: NBTTagCompound) {
|
||||
tag.setByte("shape", shape)
|
||||
tag.setString("material", materialName(material))
|
||||
}
|
||||
|
||||
override def load(tag: NBTTagCompound) {
|
||||
shape = tag.getByte("shape")
|
||||
material = materialID(tag.getString("material"))
|
||||
}
|
||||
|
||||
def isTransparent = getIMaterial.isTransparent
|
||||
|
||||
override def getLightValue = getIMaterial.getLightValue
|
||||
|
||||
override def explosionResistance(entity: Entity) =
|
||||
getIMaterial.explosionResistance(entity) * microClass.getResistanceFactor
|
||||
}
|
||||
|
||||
trait MicroblockClient
|
||||
extends Microblock
|
||||
with TIconHitEffects
|
||||
with IMicroMaterialRender {
|
||||
def getBrokenIcon(side: Int) = getIMaterial match {
|
||||
case null => Blocks.stone.getIcon(0, 0)
|
||||
case mat => mat.getBreakingIcon(side)
|
||||
}
|
||||
|
||||
// TIconHitEffects is a Java interface, so these must be declared explicitly or TMultiPart's empty versions win.
|
||||
override def addHitEffects(
|
||||
hit: MovingObjectPosition,
|
||||
effectRenderer: EffectRenderer
|
||||
) = IconHitEffects.addHitEffects(this, hit, effectRenderer)
|
||||
|
||||
override def addDestroyEffects(effectRenderer: EffectRenderer) =
|
||||
IconHitEffects.addDestroyEffects(this, effectRenderer)
|
||||
|
||||
override def renderStatic(pos: Vector3, pass: Int) = {
|
||||
if (getIMaterial.canRenderInPass(pass)) {
|
||||
render(pos, pass)
|
||||
true
|
||||
} else
|
||||
false
|
||||
}
|
||||
|
||||
def render(pos: Vector3, pass: Int)
|
||||
|
||||
override def getRenderBounds = getBounds
|
||||
}
|
||||
|
||||
trait CommonMicroblockClient
|
||||
extends CommonMicroblock
|
||||
with MicroblockClient
|
||||
with TMicroOcclusionClient {
|
||||
def render(pos: Vector3, pass: Int) {
|
||||
if (pass < 0)
|
||||
MicroblockRender.renderCuboid(pos, getIMaterial, pass, getBounds, 0)
|
||||
else
|
||||
MicroblockRender.renderCuboid(
|
||||
pos,
|
||||
getIMaterial,
|
||||
pass,
|
||||
renderBounds,
|
||||
renderMask
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
trait CommonMicroblock
|
||||
extends Microblock
|
||||
with JPartialOcclusion
|
||||
with TMicroOcclusion
|
||||
with TSlottedPart {
|
||||
def microClass: CommonMicroClass
|
||||
|
||||
def getSlot = getShape
|
||||
def getSlotMask = 1 << getSlot
|
||||
def getPartialOcclusionBoxes = Seq(getBounds)
|
||||
|
||||
override def itemClassID = microClass.getClassId
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package codechicken.microblock
|
||||
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.multipart.{
|
||||
IconHitEffects,
|
||||
JPartialOcclusion,
|
||||
TIconHitEffects,
|
||||
TSlottedPart
|
||||
}
|
||||
import net.minecraft.client.particle.EffectRenderer
|
||||
import net.minecraft.init.Blocks
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
trait MicroblockClient
|
||||
extends Microblock
|
||||
with TIconHitEffects
|
||||
with IMicroMaterialRender {
|
||||
def getBrokenIcon(side: Int) = getIMaterial match {
|
||||
case null => Blocks.stone.getIcon(0, 0)
|
||||
case mat => mat.getBreakingIcon(side)
|
||||
}
|
||||
|
||||
// TIconHitEffects is a Java interface, so these must be declared explicitly or TMultiPart's empty versions win.
|
||||
override def addHitEffects(
|
||||
hit: MovingObjectPosition,
|
||||
effectRenderer: EffectRenderer
|
||||
) = IconHitEffects.addHitEffects(this, hit, effectRenderer)
|
||||
|
||||
override def addDestroyEffects(effectRenderer: EffectRenderer) =
|
||||
IconHitEffects.addDestroyEffects(this, effectRenderer)
|
||||
|
||||
override def renderStatic(pos: Vector3, pass: Int) = {
|
||||
if (getIMaterial.canRenderInPass(pass)) {
|
||||
render(pos, pass)
|
||||
true
|
||||
} else
|
||||
false
|
||||
}
|
||||
|
||||
def render(pos: Vector3, pass: Int)
|
||||
|
||||
override def getRenderBounds = getBounds
|
||||
}
|
||||
|
||||
trait CommonMicroblockClient
|
||||
extends CommonMicroblock
|
||||
with MicroblockClient
|
||||
with TMicroOcclusionClient {
|
||||
def render(pos: Vector3, pass: Int) {
|
||||
if (pass < 0)
|
||||
MicroblockRender.renderCuboid(pos, getIMaterial, pass, getBounds, 0)
|
||||
else
|
||||
MicroblockRender.renderCuboid(
|
||||
pos,
|
||||
getIMaterial,
|
||||
pass,
|
||||
renderBounds,
|
||||
renderMask
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
trait CommonMicroblock
|
||||
extends Microblock
|
||||
with JPartialOcclusion
|
||||
with TMicroOcclusion
|
||||
with TSlottedPart {
|
||||
def microClass: CommonMicroClass
|
||||
|
||||
def getSlot = getShape
|
||||
def getSlotMask = 1 << getSlot
|
||||
def getPartialOcclusionBoxes = Seq(getBounds)
|
||||
|
||||
override def itemClassID = microClass.getClassId
|
||||
}
|
||||
Reference in new issue
Block a user