Skip to content

Commit

Permalink
Fix server crash when right clicking blocks
Browse files Browse the repository at this point in the history
Closes #124
Closes #122
  • Loading branch information
rubensworks committed Nov 20, 2019
1 parent 56d301c commit 874a81f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,23 @@ public static void addPlayerChatError(ChestMaterial material, World world, Block
if (result != null && result.getError() != null) {
addPlayerChatError(player, result.getError());
} else {
player.sendMessage(new StringTextComponent(L10NHelpers.localize(
"multiblock.colossalchests.error.unexpected")));
player.sendMessage(new TranslationTextComponent("multiblock.colossalchests.error.unexpected"));
}
}
}

public static void addPlayerChatError(PlayerEntity player, L10NHelpers.UnlocalizedString unlocalizedError) {
ITextComponent chat = new StringTextComponent("");
ITextComponent prefix = new StringTextComponent(
String.format("[%s]: ", L10NHelpers.localize("multiblock.colossalchests.error.prefix"))
).setStyle(new Style().
ITextComponent prefix = new StringTextComponent("[")
.appendSibling(new TranslationTextComponent("multiblock.colossalchests.error.prefix"))
.appendSibling(new StringTextComponent("]: "))
.setStyle(new Style().
setColor(TextFormatting.GRAY).
setHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new TranslationTextComponent("multiblock.colossalchests.error.prefix.info")
))
);
);
ITextComponent error = new StringTextComponent(unlocalizedError.localize());
chat.appendSibling(prefix);
chat.appendSibling(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, LivingE
if (stack.hasDisplayName()) {
TileUncolossalChest tile = TileHelpers.getSafeTile(world, pos, TileUncolossalChest.class).orElse(null);
if (tile != null) {
tile.setCustomName(stack.getDisplayName().getString());
tile.setCustomName(stack.getDisplayName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
Expand Down Expand Up @@ -43,8 +45,7 @@ public class TileUncolossalChest extends CyclopsTileEntity implements CyclopsTil
@Delegate
private final ITickingTile tickingTileComponent = new TickingTileComponent(this);

@NBTPersist
private String customName = null;
private ITextComponent customName = null;

private final SimpleInventory inventory;

Expand Down Expand Up @@ -83,13 +84,19 @@ public SimpleInventory getInventory() {
public void read(CompoundNBT tag) {
super.read(tag);
inventory.read(tag.getCompound("inventory"));
if (tag.contains("CustomName", Constants.NBT.TAG_STRING)) {
this.customName = ITextComponent.Serializer.fromJson(tag.getString("CustomName"));
}
}

@Override
public CompoundNBT write(CompoundNBT tag) {
CompoundNBT subTag = new CompoundNBT();
inventory.write(subTag);
tag.put("inventory", subTag);
if (this.customName != null) {
tag.putString("CustomName", ITextComponent.Serializer.toJson(this.customName));
}
return super.write(tag);
}

Expand Down Expand Up @@ -182,20 +189,16 @@ private void triggerPlayerUsageChange(int change) {
}

public boolean hasCustomName() {
return customName != null && customName.length() > 0;
return customName != null;
}

public void setCustomName(String name) {
public void setCustomName(ITextComponent name) {
this.customName = name;
}

public String getName() {
return hasCustomName() ? customName : L10NHelpers.localize("general.colossalchests.uncolossalchest");
}

@Override
public ITextComponent getDisplayName() {
return new StringTextComponent(getName());
return hasCustomName() ? customName : new TranslationTextComponent("general.colossalchests.uncolossalchest");
}

@Override
Expand Down

0 comments on commit 874a81f

Please sign in to comment.