Skip to content

Commit

Permalink
Fix: bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldenfield192 committed Jul 1, 2024
1 parent e44676c commit 717adbc
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void commonEvent(ModEvent event) {
Packet.register(ItemRailUpdatePacket::new, PacketDirection.ClientToServer);
Packet.register(MRSSyncPacket::new, PacketDirection.ServerToClient);
Packet.register(MultiblockSelectCraftPacket::new, PacketDirection.ClientToServer);
Packet.register(MultiblockSetStockPacket::new, PacketDirection.ClientToServer);
Packet.register(PreviewRenderPacket::new, PacketDirection.ServerToClient);
Packet.register(SoundPacket::new, PacketDirection.ServerToClient);
Packet.register(KeyPressPacket::new, PacketDirection.ClientToServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cam72cam.immersiverailroading.gui.components.ListSelector;
import cam72cam.immersiverailroading.multiblock.CustomCrafterMultiblock;
import cam72cam.immersiverailroading.multiblock.CustomTransporterMultiblock;
import cam72cam.immersiverailroading.net.MultiblockSetStockPacket;
import cam72cam.immersiverailroading.registry.MultiblockDefinition;
import cam72cam.immersiverailroading.tile.TileMultiblock;
import cam72cam.mod.entity.Player;
Expand Down Expand Up @@ -45,7 +46,7 @@ public void init(IScreenBuilder screen) {
180, 20, "null", pack.guiMap) {
@Override
public void onClick(String option) {
pack.setTargetTank(option);
new MultiblockSetStockPacket(option, pack).sendToServer();
}
};
Button selectButton;
Expand Down Expand Up @@ -173,7 +174,12 @@ public void draw(IScreenBuilder builder, RenderState state) {
GUIHelpers.getScreenHeight() / 4d, 0.5);
GUIHelpers.drawCenteredString(name, 0, 0, 0xFFFFFF, mat2);
mat2.translate(0, 20, 0);
String fluidType = tile.getFluidContainer().getContents().getFluid().ident.toLowerCase();
String fluidType;
try {
fluidType = tile.getFluidContainer().getContents().getFluid().ident.toLowerCase();
}catch (NullPointerException e){
fluidType = "null";
}
GUIHelpers.drawCenteredString("Fluid: " + (fluidType.equals("empty") ? "null" : fluidType),
0, 0, 0xFFFFFF, mat2);
mat2.translate(0, 20, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@
import cam72cam.immersiverailroading.model.components.ComponentProvider;
import cam72cam.immersiverailroading.model.components.ModelComponent;
import cam72cam.mod.entity.boundingbox.IBoundingBox;
import cam72cam.mod.event.CommonEvents;
import cam72cam.mod.item.Fuzzy;
import cam72cam.mod.item.ItemStack;
import cam72cam.mod.math.Vec3d;
import cam72cam.mod.math.Vec3i;
import cam72cam.mod.render.StandardModel;
import cam72cam.mod.render.obj.OBJRender;
import cam72cam.mod.render.opengl.RenderState;
import cam72cam.mod.world.World;
import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.system.CallbackI;
import util.Matrix4;

import java.util.*;
Expand All @@ -39,9 +36,7 @@ public static CargoItems get(ComponentProvider provider) {
public CargoItems(List<ModelComponent> components) {
this.components = components;
this.hitBox = new LinkedList<>();
this.components.forEach(modelComponent -> {
hitBox.add(Pair.of(modelComponent.min, modelComponent.max));
});
this.components.forEach(modelComponent -> hitBox.add(Pair.of(modelComponent.min, modelComponent.max)));
}

public List<ItemStack> getDroppedItem(World world, EntityRollingStock stock){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cam72cam.immersiverailroading.library.ModelComponentType;
import cam72cam.immersiverailroading.model.components.ComponentProvider;
import cam72cam.immersiverailroading.model.components.ModelComponent;
import cam72cam.immersiverailroading.util.VecUtil;
import cam72cam.mod.math.Vec3d;

import java.util.List;
Expand Down Expand Up @@ -43,11 +44,14 @@ public void tryToUnload(Freight freight){
double openFactor = freight.getControlPosition(this.controlGroup);
if (openFactor != 0) {
//For some stocks if we directly drop the items it will enter a cycle of being loaded and unloaded, so we'd better add an offset here
Vec3d offset = this.getPos().z > 0 ? new Vec3d(0,0,0.25) : new Vec3d(0,0,-0.25);
freight.getWorld().dropItem(
freight.cargoItems.extract(slotIndex,(int)Math.floor(openFactor * 3),false),//20~60 per sec
freight.getModelMatrix().apply(this.getPos().add(offset)),
offset.scale(0.2).rotateYaw(freight.getRotationYaw() - 90));
Vec3d offset = this.getPos().z > 0 ? new Vec3d(0,0,0.5) : new Vec3d(0,0,-0.5);
if(freight.getRotationYaw() % 90 == 0){
//TODO: We should add a flag to ItemEntity to mark that it just have been dropped...
freight.getWorld().dropItem(
freight.cargoItems.extract(slotIndex, (int) Math.floor(openFactor * 3), false),//20~60 per sec
freight.getModelMatrix().apply(this.getPos().add(offset)),
VecUtil.rotateWrongYaw(offset.scale(-0.2), freight.getRotationYaw()));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cam72cam.immersiverailroading.registry.MultiblockDefinition;
import cam72cam.immersiverailroading.tile.TileMultiblock;
import cam72cam.immersiverailroading.tile.TileRailBase;
import cam72cam.mod.ModCore;
import cam72cam.mod.entity.Player;
import cam72cam.mod.entity.boundingbox.IBoundingBox;
import cam72cam.mod.fluid.ITank;
Expand All @@ -18,9 +19,9 @@
import cam72cam.mod.util.Facing;
import cam72cam.mod.world.World;

import java.util.*;

import static cam72cam.immersiverailroading.render.multiblock.CustomMultiblockRender.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
* Added a way of customizing your own multiblocks
Expand Down Expand Up @@ -94,7 +95,7 @@ public TransporterMbInstance(World world, Vec3i origin, Rotation rot, Multiblock

@Override
public boolean onBlockActivated(Player player, Player.Hand hand, Vec3i offset) {
if (world.isServer) {
if (world.isClient) {
Vec3i pos = getPos(def.center);
GuiTypes.CUSTOM_TRANSPORT_MB_GUI.open(player, pos);
}
Expand Down Expand Up @@ -175,11 +176,13 @@ public void tick(Vec3i offset) {
vec3d = vec3d.add(-1, 0, -1);
break;
case 90:
vec3d = vec3d.add(east);
vec3d = vec3d.add(-1,0,0);
break;
case -90:
vec3d = vec3d.add(west);
case 270:
vec3d = vec3d.add(0,0,-1);
}
ModCore.info(String.valueOf((int) (this.getRotation() + 90)));
if (def.itemOutputRatioBase != 0) {
world.dropItem(handler.extract(slotIndex, def.itemOutputRatioBase, false),
vec3d.rotateYaw(this.getRotation() + 90).add(origin),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cam72cam.immersiverailroading.net;

import cam72cam.immersiverailroading.multiblock.CustomTransporterMultiblock;
import cam72cam.mod.net.Packet;
import cam72cam.mod.serialization.TagField;

public class MultiblockSetStockPacket extends Packet {
@TagField
private String name;

@TagField
private CustomTransporterMultiblock.MultiblockStorager pack;

public MultiblockSetStockPacket(String name, CustomTransporterMultiblock.MultiblockStorager packet) {
this.name = name;
this.pack = packet;
}

public MultiblockSetStockPacket() {

}

@Override
protected void handle() {
pack.setTargetTank(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class MultiblockDefinition {
this.tankCapability = fluid.getValue("tank_capability_mb").asInteger();

this.isFluidToStocks = fluid.getValue("pipes_to_stocks").asBoolean();
if(fluid.getValue("auto_interact") != null) {
if(fluid.getValue("auto_interact").asBoolean() != null) {
this.autoInteractWithStocks = fluid.getValue("auto_interact").asBoolean().toString();
}else{
this.autoInteractWithStocks = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"fluid": {
"fluid_handle_points": ["2,0,0"],
"track_handle_points": ["2,2,3"],
"pipes_to_stocks": false,
"tank_capability_mb": 20000,
"auto_interact": true
"pipes_to_stocks": true,
"tank_capability_mb": 20000
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#This is a template file in JSON format, everything after '#' is comment
#For positions, in Blender the pos is (x,y,z) and here is(-x, z, y)
#Position here (-x,y,z) takes up the space from (x,y,z) to (x+1,y+1,z+1) in Blender
{
"name": "demo1", #Required: The name of your multiblock
"type": "TRANSPORTER", #Required: The type of your multiblock(TRANSPORTER/CRAFTER/DETECTOR, now only TRANSPORTER is implied)
Expand All @@ -9,10 +8,10 @@
"height": 4, #Required: Maximum height of your mb(Blender's Z direction)
"length": 4, #Required: Maximum length of your mb(Blender's Y direction)
"structure": { #Required: structure of your mb. See CustomTransporterMultiblock$parseFuzzy to know which kind of blocks you can use.
"0,0,0": "light_engineering_block", #Position : block type
"0,0,0": "light_engineering_block", #Position : block type, positions must be integer(Vec3i)
"1,0,0": "light_engineering_block", #Currently we only have light_engineering_block, heavy_engineering_block and steels.
"2,0,0": "light_engineering_block",
"3,0,0": "light_engineering_block",
"2,0,0": "light_engineering_block", #Position here (-x,z,y) takes up the space from (x,y,z) to (x+1,y+1,z+1) in Blender
"3,0,0": "light_engineering_block",
"4,0,0": "light_engineering_block",
"0,1,0": "light_engineering_block",
"1,1,0": "light_engineering_block",
Expand All @@ -28,26 +27,27 @@
"model": "immersiverailroading:multiblocks/un1.obj", #Required: The ResourceLocation of your model

"item": { #Optional: If your multiblock can have inventory, then define me
"item_input_point": ["2,0,0"], #Required: Positions that can receive items
"item_input_point": ["2,0,0"], #Required: Positions that can receive items, position must be integer(Vec3i)
"redstone_control":true, #Required: Should item output controlled by RS power?
"redstone_control_point":"0,0,0", #Required if "redstone_control" is true: Position which can receive RS Power to control the output
"redstone_control_point":"0,0,0", #Required if "redstone_control" is true: Position which can receive RS Power to control the output, position must be integer(Vec3i)
"inventory_height": 3, #Required: The height of your inventory
"inventory_width": 10, #Required: The width of your inventory
"allow_throw_input": true, #Required: If true, you can throw items to "item_input_point" to get them loaded
"item_output_point":"4,4,5", #Required: The position of your item unloading point
"initial_velocity": "6,2,6", #Required: The initial speed when the items are thrown
"item_output_point":"4,4,5", #Required: The position of your item unloading point, positions cam be any number(Vec3d)
"initial_velocity": "6,2,6", #Required: The initial speed when the items are thrown, positions cam be any number(Vec3d)
"output_ratio_items_per_sec": 5 #Required: How many items should be thrown in a second?
},

"fluid": { #Optional: If your multiblock can have tank, then define me
"fluid_handle_points": ["2,0,0"], #Required: Positions which can interact with pipes from other mods
"track_handle_points": ["2,2,3"], #Required: Positions which can interact with stocks on nearby (Horizontal distance <= 6 and Vertical distance in [-8, 0]) tracks
"fluid_handle_points": ["2,0,0"], #Required: Positions which can interact with pipes from other mods, position must be integer(Vec3i)
"track_handle_points": ["2,2,3"], #Required: Positions which can interact with stocks on nearby (Horizontal distance <= 6 and Vertical distance in [-8, 0]) tracks, position must be integer(Vec3i)
"pipes_to_stocks": false, #Required: Is your tank a FLUID_LOADER-like(Receive fluid from pipes then send them
#to stocks)? Set false to make it a FLUID_UNLOADER-like(Receive fluid from stocks then send them to pipes)
"tank_capability_mb": 20000, #Required: The capability of your tank in milibucket
"auto_interact": true #Required: Should the multiblock interact with stocks within the bounds automatically?
#Set false to let players select the stocks they want to interact with in game
"auto_interact": true #Optional: Should the multiblock interact with stocks within the bounds automatically?
#Set true to fix it to auto mode and set false to fix it in manual mode
#Not define this to let players choose whether to manually or automatically use in game
}

#You can hold the manual on your secondary hand to see the bounds.
}
}

0 comments on commit 717adbc

Please sign in to comment.