Skip to content

Commit

Permalink
Localization mistakes && null safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailTapio committed Jan 7, 2022
1 parent 16948f3 commit c9e7cd4
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ protected void renderLabels(@NotNull MatrixStack matrixStack, int mouseX, int mo
}
if ((mouseX > x + 19 && mouseX < x + 37 && mouseY > y + 25 && mouseY < y + 43) && this.menu.breeder.hasChicken1()) {
final List<IReorderingProcessor> tooltip = new ArrayList<>();
tooltip.add(new TranslationTextComponent("text.chickens.name."+((BaseChickenEntity)this.menu.breeder.getChickenEntity1()).getChickenName()).getVisualOrderText());
final BaseChickenEntity bce = this.menu.breeder.getChickenEntity1();
if (bce != null)tooltip.add(new TranslationTextComponent("text.chickens.name."+ bce.getChickenName()).getVisualOrderText());
renderTooltip(matrixStack, tooltip, mouseX - x, mouseY - y);
}

if ((mouseX > x + 19 && mouseX < x + 37 && mouseY > y + 46 && mouseY < y + 64) && this.menu.breeder.hasChicken2()) {
final List<IReorderingProcessor> tooltip = new ArrayList<>();
tooltip.add(new TranslationTextComponent("text.chickens.name."+((BaseChickenEntity)this.menu.breeder.getChickenEntity2()).getChickenName()).getVisualOrderText());
final BaseChickenEntity bce = this.menu.breeder.getChickenEntity2();
if (bce != null)tooltip.add(new TranslationTextComponent("text.chickens.name."+ bce.getChickenName()).getVisualOrderText());
renderTooltip(matrixStack, tooltip, mouseX - x, mouseY - y);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void renderBg(@NotNull MatrixStack matrixStack, float partialTicks, in
final int x = getGuiLeft();
final int y = (height - getYSize()) / 2;
GuiUtils.drawTexturedModalRect(matrixStack,x, y, 0, 0, getXSize(), getYSize(),100);
GuiUtils.drawTexturedModalRect(matrixStack,x + 69, y + 31, 176, 0, getProgressWidth(), 12,100);
GuiUtils.drawTexturedModalRect(matrixStack,x + 69, y + 31, 176, 0, getProgressWidth(), 16,100);
if (this.menu.tileRoost.hasChickenItem()){
ChickenRenderer.render(matrixStack,x + 31,y + 32, ChickenRegistry.Types.get(this.menu.tileRoost.getChickenItemName()),minecraft);
//this.itemRenderer.renderAndDecorateItem(this.menu.tileRoost.getChickenItem(),x + 31 , y + 32 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void render(RoostTileEntity roost, float partialTicks, MatrixStack matrix
direction = roost.getBlockState().getValue(HorizontalRotatableBlock.FACING);
}

if (roost.getChickenEntity() != null) {
if (roost.getChickenEntity() != null && chicken != null) {
matrixStack.pushPose();
matrixStack.translate(0.4D, 1D / 16D, 0.2D);
matrixStack.mulPose(Vector3f.YP.rotationDegrees(direction.toYRot()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public void setPlacedBy(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull Bl
}
}



@Override
public void animateTick(@Nonnull BlockState stateIn, World world, @Nonnull BlockPos pos, @Nonnull Random rand) {
//if (!ExCompressumConfig.CLIENT.disableParticles.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
Expand All @@ -16,7 +17,6 @@
import net.minecraft.world.server.ServerWorld;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -53,9 +53,12 @@ public String getSerializedName() {



@Nullable
public void createEntity(World world,double x,double y,double z) {
world.getServer().getCommands().performCommand(new CommandSource(ICommandSource.NULL, new Vector3d(x,y,z), Vector2f.ZERO,(ServerWorld) world,4, "",
final MinecraftServer s = world.getServer();
if(s == null){
return;
}
s.getCommands().performCommand(new CommandSource(ICommandSource.NULL, new Vector3d(x,y,z), Vector2f.ZERO,(ServerWorld) world,4, "",
new StringTextComponent(""), Objects.requireNonNull(world.getServer()), null),"summon chickens:base_chicken ~ ~ ~ {Breed:'"+ entityType +"'}");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void addProbeEntityInfo(ProbeMode mode, IProbeInfo probeInfo, PlayerEntit
if (! chicken.isBaby()) {
if (chicken.type.layTime != 0) {
int secs = chicken.layTimer / 20;
probeInfo.text(new TranslationTextComponent("text.chickens.stat.eggTimer", String.format("%02d:%02d", secs / 60, secs % 60)));
probeInfo.text(new TranslationTextComponent("text.chickens.stat.probe.eggTimer", String.format("%02d:%02d", secs / 60, secs % 60)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ActionResultType interactLivingEntity(@Nonnull ItemStack stack, PlayerEnt
Util.NIL_UUID);
*/
playerIn.sendMessage(
new TranslationTextComponent("text." + MoreChickens.MODID + ".stat.gain", gene.GAIN).withStyle(TextFormatting.BLUE),
new TranslationTextComponent("text." + MoreChickens.MODID + ".stat.gain", gene.GAIN).withStyle(TextFormatting.DARK_AQUA),
Util.NIL_UUID);
playerIn.sendMessage(
new TranslationTextComponent("text." + MoreChickens.MODID + ".stat.growth", gene.GROWTH).withStyle(TextFormatting.GREEN),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.evolvefield.mods.morechickens.common.tile.BreederTileEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
Expand All @@ -26,7 +27,11 @@ public Dist getExecutingSide() {

@Override
public void executeClientSide(NetworkEvent.Context context) { //TODO check server crash
final TileEntity tileEntity = Minecraft.getInstance().level.getBlockEntity(pos);
final ClientWorld cw = Minecraft.getInstance().level;
if(cw == null){
return;
}
final TileEntity tileEntity = cw.getBlockEntity(pos);
if (tileEntity instanceof BreederTileEntity) {
BreederTileEntity breeder = (BreederTileEntity) tileEntity;
breeder.spawnParticles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,22 @@ public String getChicken2Name(){
}

public boolean hasChicken1() {
return !chicken1.isEmpty();
return chicken1 !=null && !chicken1.isEmpty();
}

public boolean hasChicken2() {
return !chicken2.isEmpty();
return chicken2 != null && !chicken2.isEmpty();
}

@Nullable
public BaseChickenEntity getChickenEntity1() {
if (chickenEntity1 == null && !chicken1.isEmpty()) {
chickenEntity1 = getChicken(level, chicken1);
}
return chickenEntity1;
}

@Nullable
public BaseChickenEntity getChickenEntity2() {
if (chickenEntity2 == null && !chicken2.isEmpty()) {
chickenEntity2 = getChicken(level, chicken2);
Expand Down Expand Up @@ -250,6 +252,9 @@ private boolean addChicken() {
if(level == null){
return false;
}
if(getChickenEntity1() == null || getChickenEntity2() == null){
return false;
}
for (int i = 0; i < outputInventory.size(); i++) {
if (outputInventory.get(i).isEmpty()) {
final String typeA = getChicken1().getOrCreateTag().getString("Type");
Expand Down Expand Up @@ -283,6 +288,9 @@ else if(typeA.equals("vanilla") || typeB.equals("vanilla")){
}

public boolean canBreed() {
if (getChickenEntity1() == null || getChickenEntity2() == null){
return false;
}
if (!hasChicken1() || !hasChicken2()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,18 @@ public void setChickenItem(ItemStack chicken1) {
sync();
}

@Nullable
public ItemStack getChickenItem() {
return chickenItem;
}

@Nullable
public String getChickenItemName(){
return getChickenItem().getOrCreateTag().getString("Name");
return getChickenItem() != null ? getChickenItem().getOrCreateTag().getString("Name") : null;
}

public boolean hasChickenItem() {
return !chickenItem.isEmpty();
return chickenItem != null &&!chickenItem.isEmpty();
}

@Nullable
Expand Down Expand Up @@ -199,6 +201,9 @@ private void updateTimerIfNeeded() {
}
}
public boolean canLay() {
if (getChickenEntity() == null){
return false;
}
if (!hasChickenItem() ) {
return false;
}
Expand Down Expand Up @@ -233,6 +238,9 @@ private void spawnChickenDropIfNeeded() {
}

private void resetTimer() {
if(getChickenItem() == null){
return;
}
final String type = getChickenItem().getOrCreateTag().getString("Type");
final String name = getChickenItem().getOrCreateTag().getString("Name");
final ChickenData data = ChickenUtils.getChickenDataByName(name);
Expand All @@ -251,6 +259,9 @@ else if(type.equals("modded"))
}

private boolean addLoot() {
if(getChickenItem() == null){
return false;
}
for (int i = 0; i < outputInventory.size(); i++) {
if (outputInventory.get(i).isEmpty()) {
final String type = getChickenItem().getOrCreateTag().getString("Type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cn.evolvefield.mods.morechickens.common.data.custom.ChickenReloadListener;
import cn.evolvefield.mods.morechickens.init.ModEntities;
import mezz.jei.api.ingredients.IIngredientHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TranslationTextComponent;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -51,7 +52,8 @@ public String getModId(@Nonnull EntityIngredient type) {
@Nonnull
@Override
public String getResourceId(@Nonnull EntityIngredient type) {
return ModEntities.BASE_CHICKEN.get().getRegistryName().getPath();
final ResourceLocation rl = ModEntities.BASE_CHICKEN.get().getRegistryName();
return (rl != null)?rl.getPath():"";
}

@Nonnull
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/chickens/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"text.chickens.stat.gain": "Gain: %f",
"text.chickens.stat.growth": "Growth: %f",
"text.chickens.stat.strength": "Strength: %f",
"text.chickens.stat.probe.eggTimer": "Time Until Next Egg: %f ",
"text.chickens.stat.eggTimer": "Minutes Until Next Egg: %f minutes",


Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/assets/chickens/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"text.chickens.stat.gain": "产出值: %f",
"text.chickens.stat.growth": "成长度: %f",
"text.chickens.stat.strength": "基因强度: %f",
"text.chickens.stat.probe.eggTimer": "距离产出下个鸡蛋: %f ",
"text.chickens.stat.eggTimer": "距离产出下个鸡蛋: %f 分钟",


Expand All @@ -93,10 +94,10 @@
"text.chickens.name.sand": "沙子鸡",
"text.chickens.name.oak": "原木鸡",
"text.chickens.name.flint": "燧石鸡",
"text.chickens.name.quartz": "下届石英鸡",
"text.chickens.name.quartz": "下界石英鸡",
"text.chickens.name.soul_sand": "灵魂沙鸡",

"text.chickens.name.clay": "粘土鸡",
"text.chickens.name.clay": "黏土鸡",
"text.chickens.name.leather": "皮革鸡",
"text.chickens.name.string": "线鸡",
"text.chickens.name.slime": "史莱姆鸡",
Expand All @@ -122,7 +123,7 @@

"text.chickens.name.redstone": "红石鸡",
"text.chickens.name.iron": "铁鸡",
"text.chickens.name.glowstone": "萤石鸡",
"text.chickens.name.glowstone": "荧石鸡",
"text.chickens.name.coal": "煤鸡",
"text.chickens.name.gunpowder": "火药鸡",
"text.chickens.name.snowball": "雪球鸡",
Expand All @@ -133,7 +134,7 @@
"text.chickens.name.water": "水鸡",

"text.chickens.name.diamond": "钻石鸡",
"text.chickens.name.wart": "地狱疮鸡",
"text.chickens.name.wart": "下界疣鸡",
"text.chickens.name.blaze": "烈焰棒鸡",
"text.chickens.name.obsidian": "黑曜石鸡",
"text.chickens.name.prism_shard": "海晶碎片鸡",
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/chickens/models/block/breeder.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"1": "chickens:blocks/glass",
"4": "chickens:blocks/curtain_side",
"5": "chickens:blocks/plain_face",
"7": "chickens:blocks/hay_floor"
"7": "chickens:blocks/hay_floor",
"particle": "chickens:blocks/plain_face"
},
"elements": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"textures": {
"particle": "minecraft:item/flint"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"textures": {
"particle": "minecraft:block/oak_sapling"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"textures": {
"particle": "minecraft:item/quartz"
Expand Down

0 comments on commit c9e7cd4

Please sign in to comment.