Skip to content

Commit

Permalink
add fuse time display to tnt carts
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Jul 21, 2023
1 parent 9d8ad15 commit f87d543
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
8 changes: 5 additions & 3 deletions src/main/java/mendedminecarts/MendedMinecartsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static <T extends Setting> T addSetting(T setting) {
public static final BooleanSetting DISPLAY_CART_DATA_WOBBLE = new BooleanSetting("Wobble", false, Text.translatable("mendedminecarts.display_cart_data.wobble.description"));
public static final BooleanSetting DISPLAY_CART_DATA_RIDEABLE = new BooleanSetting("Rideable", false, Text.translatable("mendedminecarts.display_cart_data.is_rideable.description"));
public static final IntegerSetting DISPLAY_CART_DATA_PRECISION = new IntegerSetting("DataPrecision", 4, Text.translatable("mendedminecarts.data_precision.description"));
public static final BooleanSetting DISPLAY_CART_DATA_FUSE = new BooleanSetting("Fuse", false, Text.translatable("mendedminecarts.fuse.description"));


public static final SettingGroup DISPLAY_CART_DATA = addSetting(
Expand All @@ -80,7 +81,8 @@ public static <T extends Setting> T addSetting(T setting) {
DISPLAY_CART_DATA_WOBBLE,
DISPLAY_CART_DATA_RIDEABLE,
DISPLAY_CART_DATA_PRECISION,
DISPLAY_CART_DATA_POS_BINARY
DISPLAY_CART_DATA_POS_BINARY,
DISPLAY_CART_DATA_FUSE
)
);

Expand All @@ -94,8 +96,8 @@ public static <T extends Setting> T addSetting(T setting) {
public static final BooleanSetting ROTATE_CART_TO_RAIL = addSetting(new BooleanSetting("RotateCartToRail", false, Text.translatable("mendedminecarts.rotate_cart_to_rail.description")));
public static final BooleanSetting EXPLODING_CART_FIX = addSetting(new BooleanSetting("ExplodeRailsFix", false, Text.translatable("mendedminecarts.explode_rail_fix.description")));
public static final BooleanSetting NO_CART_ITEM_CAP = addSetting(new BooleanSetting("NoCartItemCap", false, Text.translatable("mendedminecarts.no_cart_item_cap.description")));
public static final BooleanSetting LAVA_CAULDRON_KILLS_TNT_CART = addSetting(new BooleanSetting("LavaCauldonKillsTNTCarts", false, Text.translatable("mendedminecarts.lava_cauldron_kills_tnt_carts")));
public static final BooleanSetting RAIL_PLACEMENT = addSetting(new BooleanSetting("RailPlacement", false, Text.translatable("mendedminecarts.rail_placement")));
public static final BooleanSetting LAVA_CAULDRON_KILLS_TNT_CART = addSetting(new BooleanSetting("LavaCauldonKillsTNTCarts", false, Text.translatable("mendedminecarts.lava_cauldron_kills_tnt_carts.description")));
public static final BooleanSetting RAIL_PLACEMENT = addSetting(new BooleanSetting("RailPlacement", false, Text.translatable("mendedminecarts.rail_placement.description")));

@Override
public void onInitialize() {
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/mendedminecarts/MinecartDisplayData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
import net.minecraft.entity.vehicle.FurnaceMinecartEntity;
import net.minecraft.entity.vehicle.HopperMinecartEntity;
import net.minecraft.entity.vehicle.StorageMinecartEntity;
import net.minecraft.entity.vehicle.*;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList;
Expand All @@ -27,7 +25,8 @@
* Stores last received server side minecart data
*/
public record MinecartDisplayData(Vec3d pos, Box boundingBox, Vec3d velocity, boolean onGround, int fillLevel,
double slowdownFactor, double estimatedDistance, boolean hopperLocked, float wobble, boolean rideable,
double slowdownFactor, double estimatedDistance, boolean hopperLocked, float wobble,
boolean rideable, int fuseTime,
AbstractMinecartEntity entity) {

public static MinecartDisplayData fromNBT(AbstractMinecartEntityAccess entity, NbtCompound nbt) {
Expand All @@ -51,7 +50,13 @@ public static MinecartDisplayData fromNBT(AbstractMinecartEntityAccess entity, N

boolean rideable = ((AbstractMinecartEntity) entity).getType() == EntityType.MINECART && !((AbstractMinecartEntity) entity).hasPassengers();
Box boxAt = ((Entity) entity).getType().getDimensions().getBoxAt(pos.x, pos.y, pos.z);
return new MinecartDisplayData(pos, boxAt, velocity, onGround, fillLevel, slowdown, estimatedDistance, hopperLocked, wobble, rideable, (AbstractMinecartEntity) entity);

int fuseTime = Integer.MIN_VALUE;
if (nbt.contains("TNTFuse", NbtElement.NUMBER_TYPE)) {
fuseTime = nbt.getInt("TNTFuse");
}

return new MinecartDisplayData(pos, boxAt, velocity, onGround, fillLevel, slowdown, estimatedDistance, hopperLocked, wobble, rideable, fuseTime, (AbstractMinecartEntity) entity);
}

private static int getComparatorOutput(StorageMinecartEntity inventory, NbtCompound nbtCompound) {
Expand Down Expand Up @@ -270,6 +275,9 @@ public ArrayList<Text> getInfoTexts() {
if (MendedMinecartsMod.DISPLAY_CART_DATA_RIDEABLE.isEnabled() && this.entity().getType() == EntityType.MINECART) {
infoTexts.add(Text.translatable("mendedminecarts.is_rideable").append(": ").append(String.valueOf(this.rideable())));
}
if (MendedMinecartsMod.DISPLAY_CART_DATA_FUSE.isEnabled() && this.entity().getType() == EntityType.TNT_MINECART && this.fuseTime() != Integer.MIN_VALUE) {
infoTexts.add(Text.translatable("mendedminecarts.fuse").append(": ").append(String.valueOf(this.fuseTime())));
}


return infoTexts;
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/assets/mendedminecarts/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"mendedminecarts.display_cart_data.hopper_pickup_box.description": "Displays the item pickup volume of hopper minecarts.",
"mendedminecarts.display_cart_data.hopper_extract_volume.description": "Displays the inventory entity search volume of hopper minecarts.",
"mendedminecarts.display_cart_data.hopper_extract_block.description": "Displays the inventory block hopper minecarts interact with.",
"mendedminecarts.display_cart_data.wobble.description": "Displays the wobble (health) of carts..",
"mendedminecarts.display_cart_data.wobble.description": "Displays the wobble (health) of carts.",
"mendedminecarts.display_cart_data.description": "Displays server-side information above minecarts.",
"mendedminecarts.derailing_cart_fix_demo.description": "Prevents minecarts from derailing",
"mendedminecarts.rotate_cart_to_rail.description": "Rotates minecarts on non-curved rails to fix unexpected pushing behavior of minecarts",
Expand All @@ -45,6 +45,8 @@
"mendedminecarts.wobble": "Wobble",
"mendedminecarts.is_rideable": "Rideable",
"mendedminecarts.no_cart_item_cap.description": "Remove the item cap of minecart inventories and item stacks. Adds a \"CustomCount\" integer attribute to the NBT of ItemStacks.",
"mendedminecarts.lava_cauldron_kills_tnt_carts": "Lava cauldrons don't make TNT carts explode.",
"mendedminecarts.rail_placement": "Better rail placement when player is sneaking. Sloped rails like top slabs, curved rails when clicking in the corner of a block."
"mendedminecarts.lava_cauldron_kills_tnt_carts.description": "Lava cauldrons don't make TNT carts explode.",
"mendedminecarts.rail_placement.description": "Better rail placement when player is sneaking. Sloped rails like top slabs, curved rails when clicking in the corner of a block.",
"mendedminecarts.fuse.description": "Displays the fuse time of TNT minecarts.",
"mendedminecarts.fuse": "Fuse"
}

0 comments on commit f87d543

Please sign in to comment.