Skip to content

Commit

Permalink
Deprecate server-unsafe UnlocalizedString in favor of ITextComponent
Browse files Browse the repository at this point in the history
A follow-up fix for 874a81f

Closes #127
  • Loading branch information
rubensworks committed Nov 23, 2019
1 parent 7295788 commit 623c84f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ minecraft_version=1.14.4
forge_version=28.1.1
mcp_mappings_channel=snapshot
mcp_mappings_version=20190719-1.14.3
cyclopscore_version=1.6.0-1017
cyclopscore_version=1.6.0-1020
release_type=release
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.cyclops.cyclopscore.block.multi.CubeDetector;
import org.cyclops.cyclopscore.block.multi.DetectionResult;
import org.cyclops.cyclopscore.datastructure.Wrapper;
import org.cyclops.cyclopscore.helper.L10NHelpers;
import org.cyclops.cyclopscore.helper.LocationHelpers;
import org.cyclops.cyclopscore.helper.MinecraftHelpers;
import org.cyclops.cyclopscore.helper.TileHelpers;
Expand Down Expand Up @@ -217,7 +216,7 @@ public static void addPlayerChatError(ChestMaterial material, World world, Block
}
}

public static void addPlayerChatError(PlayerEntity player, L10NHelpers.UnlocalizedString unlocalizedError) {
public static void addPlayerChatError(PlayerEntity player, ITextComponent error) {
ITextComponent chat = new StringTextComponent("");
ITextComponent prefix = new StringTextComponent("[")
.appendSibling(new TranslationTextComponent("multiblock.colossalchests.error.prefix"))
Expand All @@ -229,7 +228,6 @@ public static void addPlayerChatError(PlayerEntity player, L10NHelpers.Unlocaliz
new TranslationTextComponent("multiblock.colossalchests.error.prefix.info")
))
);
ITextComponent error = new StringTextComponent(unlocalizedError.localize());
chat.appendSibling(prefix);
chat.appendSibling(error);
player.sendMessage(chat);
Expand Down Expand Up @@ -282,7 +280,7 @@ public MaterialValidationAction() {
}

@Override
public L10NHelpers.UnlocalizedString onValidate(BlockPos blockPos, BlockState blockState) {
public ITextComponent onValidate(BlockPos blockPos, BlockState blockState) {
ChestMaterial material = null;
if (blockState.getBlock() instanceof IBlockChestMaterial) {
material = ((IBlockChestMaterial) blockState.getBlock()).getMaterial();
Expand All @@ -291,10 +289,10 @@ public L10NHelpers.UnlocalizedString onValidate(BlockPos blockPos, BlockState bl
requiredMaterial.set(material);
return null;
}
return requiredMaterial.get() == material ? null : new L10NHelpers.UnlocalizedString(
"multiblock.colossalchests.error.material", new L10NHelpers.UnlocalizedString(material.getUnlocalizedName()),
return requiredMaterial.get() == material ? null : new TranslationTextComponent(
"multiblock.colossalchests.error.material", new TranslationTextComponent(material.getUnlocalizedName()),
LocationHelpers.toCompactString(blockPos),
new L10NHelpers.UnlocalizedString(requiredMaterial.get().getUnlocalizedName()));
new TranslationTextComponent(requiredMaterial.get().getUnlocalizedName()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import org.cyclops.colossalchests.Advancements;
Expand Down Expand Up @@ -68,15 +70,15 @@ public ActionResultType onItemUseFirst(ItemStack itemStack, ItemUseContext conte
if(context.getWorld().isRemote()) {
return ActionResultType.PASS;
}
ColossalChest.addPlayerChatError(context.getPlayer(), new L10NHelpers.UnlocalizedString(
ColossalChest.addPlayerChatError(context.getPlayer(), new TranslationTextComponent(
"multiblock.colossalchests.error.upgradeLimit"));
return ActionResultType.FAIL;
}

// Loop over the up/downgrade tiers until one works.
L10NHelpers.UnlocalizedString firstError = null;
ITextComponent firstError = null;
do {
L10NHelpers.UnlocalizedString error = attemptTransform(context.getWorld(), context.getPos(), context.getPlayer(), tile, newType, tile.getMaterial(), context.getHand());
ITextComponent error = attemptTransform(context.getWorld(), context.getPos(), context.getPlayer(), tile, newType, tile.getMaterial(), context.getHand());
if (error != null) {
if (firstError == null) {
firstError = error;
Expand All @@ -92,7 +94,7 @@ public ActionResultType onItemUseFirst(ItemStack itemStack, ItemUseContext conte
return context.getWorld().isRemote() ? ActionResultType.PASS : ActionResultType.SUCCESS;
}

protected L10NHelpers.UnlocalizedString attemptTransform(final World world, BlockPos pos, PlayerEntity player,
protected ITextComponent attemptTransform(final World world, BlockPos pos, PlayerEntity player,
final TileColossalChest tile, final ChestMaterial newType,
final ChestMaterial currentType, Hand hand) {
Vec3i size = tile.getSize();
Expand Down Expand Up @@ -124,16 +126,16 @@ protected L10NHelpers.UnlocalizedString attemptTransform(final World world, Bloc
ItemStack requiredWalls = new ItemStack(newType.getBlockWall(), requiredWallsCount.get());

if (validMaterial == null) {
return new L10NHelpers.UnlocalizedString("multiblock.colossalchests.error.unexpected");
return new TranslationTextComponent("multiblock.colossalchests.error.unexpected");
}

// Check required items in inventory
if (!(consumeItems(player, requiredCores, true)
&& consumeItems(player, requiredInterfaces, true)
&& consumeItems(player, requiredWalls, true))) {
return new L10NHelpers.UnlocalizedString(
return new TranslationTextComponent(
"multiblock.colossalchests.error.upgrade", requiredCores.getCount(),
requiredInterfaces.getCount(), requiredWalls.getCount(), new L10NHelpers.UnlocalizedString(newType.getUnlocalizedName()));
requiredInterfaces.getCount(), requiredWalls.getCount(), new TranslationTextComponent(newType.getUnlocalizedName()));
}

// Actually consume the items
Expand Down

0 comments on commit 623c84f

Please sign in to comment.