Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Edivad99 committed Sep 27, 2023
1 parent 773beca commit 45b7640
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 205 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.1 2023-09-26T11:16:14.330781 Languages: en_us
6c90e792080e4adf933d2540dea658da1fa5b843 assets/railcraft/lang/en_us.json
// 1.20.1 2023-09-27T09:49:31.834652 Languages: en_us
4380836cabe6eaacc8a7721d52743012ed2e8b28 assets/railcraft/lang/en_us.json
1 change: 1 addition & 0 deletions src/generated/resources/assets/railcraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@
"tips.railcraft.firestone.charged": "Filled with energy, you only need to exert your will onto it to release it's blistering heat...",
"tips.railcraft.firestone.cut": "Still its energies rage out of control...",
"tips.railcraft.firestone.empty": "Its energies controlled, it could be useful if you could recharge it...",
"tips.railcraft.firestone.ore": "It lies in the lava beds in the nether",
"tips.railcraft.firestone.raw": "It quickens in your hands, you can feel it in the very air around you...",
"tips.railcraft.fluid_loader": "Loads fluids into carts",
"tips.railcraft.fluid_unloader": "Unloads fluids from carts",
Expand Down
197 changes: 66 additions & 131 deletions src/main/java/mods/railcraft/Translations.java

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/main/java/mods/railcraft/charge/ChargeSavedData.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static ChargeSavedData getFor(Charge network, ServerLevel level) {
var manager = new ChargeSavedData();
manager.load(tag);
return manager;

}, ChargeSavedData::new, DATA_TAG_PREFIX + network.getSerializedName());
}

Expand All @@ -47,9 +46,7 @@ private void load(CompoundTag tag) {
for (int i = 0; i < batteriesTag.size(); i++) {
var entryTag = batteriesTag.getCompound(i);
var pos = NbtUtils.readBlockPos(entryTag.getCompound("pos"));
if (pos != null) {
this.chargeLevels.put(pos, entryTag.getInt("value"));
}
this.chargeLevels.put(pos, entryTag.getInt("value"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ public GaugeRenderer(GaugeWidget widget) {
super(widget);
}


@Override
public void render(ResourceLocation widgetLocation, GuiGraphics guiGraphics, int centreX,
int centreY, int mouseX, int mouseY) {
int scale = Math.round((float) (this.widget.getMeasurement()
* (double) (this.widget.isVertical() ? this.widget.h : this.widget.w)));
int scale = Math.round(this.widget.getMeasurement() *
(this.widget.isVertical() ? this.widget.h : this.widget.w));
if (this.widget.isVertical()) {
guiGraphics.blit(widgetLocation, centreX + this.widget.x,
centreY + this.widget.y + this.widget.h - scale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ private void tipsTranslations() {
this.add(Translations.Tips.RAW_FIRESTONE,
"It quickens in your hands, you can feel it in the very air around you...");
this.add(Translations.Tips.CUT_FIRESTONE, "Still its energies rage out of control...");
this.add(Translations.Tips.FIRESTONE_ORE, "It lies in the lava beds in the nether");
this.add(Translations.Tips.CURRENT_MODE, "Current Mode:");

this.add(LockingMode.LOCKDOWN.getTranslationKey(), "Lockdown");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public FluidFueledSteamBoilerMenu(int id, Inventory inventory,
this.addInventorySlots(inventory, 166);

this.addDataSlot(new SimpleDataSlot(
() -> (int) Math.round(this.module.getBoiler().getBurnTime()),
() -> Math.round(this.module.getBoiler().getBurnTime()),
this.module.getBoiler()::setBurnTime));

this.addDataSlot(new SimpleDataSlot(
() -> (int) Math.round(this.module.getBoiler().getCurrentItemBurnTime()),
() -> Math.round(this.module.getBoiler().getCurrentItemBurnTime()),
this.module.getBoiler()::setCurrentItemBurnTime));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class LocomotiveMenu<T extends Locomotive> extends RailcraftMenu {
public static final int DEFAULT_HEIGHT = 161;

private final T locomotive;
public String ownerName;

public LocomotiveMenu(@Nullable MenuType<?> type, int id, Inventory playerInv,
T locomotive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public SolidFueledSteamBoilerMenu(int id, Inventory inventory,
this.addInventorySlots(inventory, 166);

this.addDataSlot(new SimpleDataSlot(
() -> (int) Math.round(this.module.getBoiler().getBurnTime()),
() -> Math.round(this.module.getBoiler().getBurnTime()),
this.module.getBoiler()::setBurnTime));

this.addDataSlot(new SimpleDataSlot(
() -> (int) Math.round(this.module.getBoiler().getCurrentItemBurnTime()),
() -> Math.round(this.module.getBoiler().getCurrentItemBurnTime()),
this.module.getBoiler()::setCurrentItemBurnTime));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public SteamLocomotiveMenu(int id, Inventory inventory, SteamLocomotive locomot
this.addSlot(new RailcraftSlot(this.getLocomotive(), 6, 80, 56)); // Fuel

this.addDataSlot(new SimpleDataSlot(
() -> (int) Math.round(locomotive.boiler().getBurnTime()),
() -> Math.round(locomotive.boiler().getBurnTime()),
this.getLocomotive().boiler()::setBurnTime));

this.addDataSlot(new SimpleDataSlot(
() -> (int) Math.round(locomotive.boiler().getCurrentItemBurnTime()),
() -> Math.round(locomotive.boiler().getCurrentItemBurnTime()),
this.getLocomotive().boiler()::setCurrentItemBurnTime));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ public TunnelBoreMenu(int id, Inventory inventory, TunnelBore tunnelBore) {

this.addInventorySlots(inventory, IMAGE_HEIGHT);

this.addDataSlot(new SimpleDataSlot(
tunnelBore::getBurnTime, tunnelBore::setBurnTime));

this.addDataSlot(new SimpleDataSlot(
tunnelBore::getFuel, tunnelBore::setFuel));
this.addDataSlot(new SimpleDataSlot(tunnelBore::getBurnTime, tunnelBore::setBurnTime));
this.addDataSlot(new SimpleDataSlot(tunnelBore::getFuel, tunnelBore::setFuel));
}

public TunnelBore getTunnelBore() {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/mods/railcraft/world/item/FirestoneOreBlockItem.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package mods.railcraft.world.item;

import java.util.List;
import org.jetbrains.annotations.Nullable;
import mods.railcraft.Translations;
import mods.railcraft.world.level.block.RailcraftBlocks;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;

Expand All @@ -23,4 +29,11 @@ public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotI
FirestoneItem.trySpawnFire(player.level(), player.blockPosition(), stack, player);
}
}

@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip,
TooltipFlag flag) {
tooltip.add(Component.translatable(Translations.Tips.FIRESTONE_ORE)
.withStyle(ChatFormatting.GRAY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public VoxelShape getShape(BlockState state, BlockGetter source, BlockPos pos,
return SHAPE;
}


@Override
public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGetter blockGetter,
BlockPos pos, Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

public enum Connection implements StringRepresentable {

NONE("name"),
NONE("none"),
SINGLE("single"),
DOUBLE("double");

private final String name;

private Connection(String name) {
Connection(String name) {
this.name = name;
}

Expand Down
39 changes: 18 additions & 21 deletions src/main/java/mods/railcraft/world/level/block/post/PostBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.EnumMap;
import java.util.Map;
import java.util.function.ToIntFunction;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import mods.railcraft.tags.RailcraftTags;
Expand All @@ -15,7 +14,6 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.LeadItem;
import net.minecraft.world.item.context.BlockPlaceContext;
Expand Down Expand Up @@ -120,8 +118,7 @@ public VoxelShape getBlockSupportShape(BlockState blockState, BlockGetter level,
}

public final int getShapeIndex(BlockState blockState) {
return this.stateToIndex.computeIfAbsent(blockState,
(ToIntFunction<BlockState>) this::computeShapeIndex);
return this.stateToIndex.computeIfAbsent(blockState, this::computeShapeIndex);
}

protected int computeShapeIndex(BlockState blockState) {
Expand Down Expand Up @@ -149,26 +146,26 @@ protected int computeShapeIndex(BlockState blockState) {
public InteractionResult use(BlockState blockState, Level level, BlockPos pos,
Player player, InteractionHand hand, BlockHitResult rayTraceResult) {
if (level.isClientSide()) {
ItemStack itemStack = player.getItemInHand(hand);
return itemStack.getItem() == Items.LEAD ? InteractionResult.SUCCESS : InteractionResult.PASS;
var itemStack = player.getItemInHand(hand);
return itemStack.is(Items.LEAD) ? InteractionResult.SUCCESS : InteractionResult.PASS;
} else {
return LeadItem.bindPlayerMobs(player, level, pos);
}
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Level level = context.getLevel();
BlockPos blockPos = context.getClickedPos();
FluidState fluidState = level.getFluidState(context.getClickedPos());
BlockPos northPos = blockPos.north();
BlockPos eastPos = blockPos.east();
BlockPos southPos = blockPos.south();
BlockPos westPos = blockPos.west();
BlockState northState = level.getBlockState(northPos);
BlockState eastState = level.getBlockState(eastPos);
BlockState southState = level.getBlockState(southPos);
BlockState westState = level.getBlockState(westPos);
var level = context.getLevel();
var blockPos = context.getClickedPos();
var fluidState = level.getFluidState(context.getClickedPos());
var northPos = blockPos.north();
var eastPos = blockPos.east();
var southPos = blockPos.south();
var westPos = blockPos.west();
var northState = level.getBlockState(northPos);
var eastState = level.getBlockState(eastPos);
var southState = level.getBlockState(southPos);
var westState = level.getBlockState(westPos);
return super.getStateForPlacement(context)
.setValue(COLUMN, this.getColumn(level, blockPos))
.setValue(NORTH, this.getConnection(northState,
Expand Down Expand Up @@ -214,10 +211,10 @@ public Connection getConnection(BlockState blockState, boolean sturdy, Direction
}

public Column getColumn(BlockGetter level, BlockPos blockPos) {
BlockPos abovePos = blockPos.above();
BlockState aboveState = level.getBlockState(abovePos);
BlockPos belowPos = blockPos.below();
BlockState belowState = level.getBlockState(belowPos);
var abovePos = blockPos.above();
var aboveState = level.getBlockState(abovePos);
var belowPos = blockPos.below();
var belowState = level.getBlockState(belowPos);

if (aboveState.is(BlockTags.RAILS)) {
return Column.PLATFORM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public SteamBoilerBlock(Properties properties) {
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState,
BlockEntityType<T> type) {
return level.isClientSide() ? null
: createTickerHelper(type, this.getBlockEntityType(),
SteamBoilerBlockEntity::serverTick);
return level.isClientSide()
? null
: createTickerHelper(type, this.getBlockEntityType(), SteamBoilerBlockEntity::serverTick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public enum ConnectionType implements StringRepresentable {

private final String name;

private ConnectionType(String name) {
ConnectionType(String name) {
this.name = name;
}

Expand Down
45 changes: 20 additions & 25 deletions src/main/java/mods/railcraft/world/signal/TokenRingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import net.minecraft.core.BlockPos;
Expand All @@ -18,7 +15,7 @@

public class TokenRingManager extends SavedData {

public static final String DATA_TAG = "railcraft.tokens";
private static final String DATA_TAG = "railcraft.tokens";

private final ServerLevel level;
private final Map<UUID, SimpleTokenRing> tokenRings = new HashMap<>();
Expand All @@ -29,43 +26,41 @@ public TokenRingManager(ServerLevel level) {
}

private void load(CompoundTag data) {
List<Tag> tokenRingList = data.getList("tokenRings", Tag.TAG_COMPOUND);
for (Tag nbt : tokenRingList) {
CompoundTag entry = (CompoundTag) nbt;
UUID id = entry.getUUID("id");
SimpleTokenRing tokenRing = new SimpleTokenRing(this.level, this, id);
var tokenRingList = data.getList("tokenRings", Tag.TAG_COMPOUND);
for (int i = 0; i < tokenRingList.size(); i++) {
var entry = tokenRingList.getCompound(i);
var id = entry.getUUID("id");
var tokenRing = new SimpleTokenRing(this.level, this, id);
this.tokenRings.put(id, tokenRing);
List<Tag> signalList = entry.getList("signals", Tag.TAG_COMPOUND);
Set<BlockPos> signalPositions = signalList.stream()
var signalList = entry.getList("signals", Tag.TAG_COMPOUND);
var signalPositions = signalList.stream()
.map(CompoundTag.class::cast)
.map(NbtUtils::readBlockPos)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
tokenRing.loadSignals(signalPositions);
List<Tag> cartList = entry.getList("carts", Tag.TAG_COMPOUND);
Set<UUID> carts = cartList.stream()
var cartList = entry.getList("carts", Tag.TAG_COMPOUND);
var carts = cartList.stream()
.map(CompoundTag.class::cast)
.map(signal -> signal.getUUID("cart"))
.filter(Objects::nonNull)
.collect(Collectors.toSet());
tokenRing.loadCarts(carts);
}
}

@Override
public CompoundTag save(CompoundTag data) {
ListTag tokenRingList = new ListTag();
for (SimpleTokenRing tokenRing : tokenRings.values()) {
CompoundTag tokenData = new CompoundTag();
var tokenRingList = new ListTag();
for (var tokenRing : tokenRings.values()) {
var tokenData = new CompoundTag();
tokenData.putUUID("id", tokenRing.getId());
ListTag signalList = new ListTag();
for (BlockPos pos : tokenRing.peers()) {
var signalList = new ListTag();
for (var pos : tokenRing.peers()) {
signalList.add(NbtUtils.writeBlockPos(pos));
}
tokenData.put("signals", signalList);
ListTag cartList = new ListTag();
for (UUID uuid : tokenRing.getTrackedCarts()) {
CompoundTag cart = new CompoundTag();
var cartList = new ListTag();
for (var uuid : tokenRing.getTrackedCarts()) {
var cart = new CompoundTag();
cart.putUUID("cart", uuid);
cartList.add(cart);
}
Expand All @@ -80,8 +75,9 @@ public void tick(ServerLevel level) {
this.clock++;
if (this.clock >= 32) {
this.clock = 0;
if (this.tokenRings.entrySet().removeIf(e -> e.getValue().isOrphaned(level)))
if (this.tokenRings.entrySet().removeIf(e -> e.getValue().isOrphaned(level))) {
this.setDirty();
}
this.tokenRings.values().forEach(SimpleTokenRing::tick);
}
}
Expand All @@ -100,7 +96,6 @@ public static TokenRingManager get(ServerLevel level) {
var manager = new TokenRingManager(level);
manager.load(tag);
return manager;

}, () -> new TokenRingManager(level), DATA_TAG);
}
}

0 comments on commit 45b7640

Please sign in to comment.