Skip to content

Commit

Permalink
Null safety && Analyzer optimization && finalize some components
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailTapio committed Jan 6, 2022
1 parent 7989df3 commit a368209
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,26 @@ protected void renderLabels(@NotNull MatrixStack matrixStack, int mouseX, int mo

@Override
protected void renderBg(@NotNull MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) {
RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
assert this.minecraft != null;
this.minecraft.getTextureManager().bind(BACKGROUND);
int x = getGuiLeft();
int y = (height - getYSize()) / 2;

GuiUtils.drawTexturedModalRect(matrixStack,x, y, 0, 0, getXSize(), getYSize(),100);
GuiUtils.drawTexturedModalRect(matrixStack,x + 81, y + 34, 176, 0, getProgressWidth(), 12,100);
if (this.menu.breeder.hasChicken1()){
ChickenRenderer.render(matrixStack,x + 19,y + 25, ChickenRegistry.Types.get(this.menu.breeder.getChicken1Name()),minecraft);
//this.itemRenderer.renderAndDecorateItem(this.menu.breeder.getChicken1(),x + 19 , y + 25 );
}
if (this.menu.breeder.hasChicken2()){
ChickenRenderer.render(matrixStack,x + 19,y + 46, ChickenRegistry.Types.get(this.menu.breeder.getChicken2Name()),minecraft);
//this.itemRenderer.renderAndDecorateItem(this.menu.breeder.getChicken2(),x + 19 , y + 46 );
if (this.minecraft != null) {
RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
this.minecraft.getTextureManager().bind(BACKGROUND);
final int x = getGuiLeft();
final int y = (height - getYSize()) / 2;
GuiUtils.drawTexturedModalRect(matrixStack,x, y, 0, 0, getXSize(), getYSize(),100);
GuiUtils.drawTexturedModalRect(matrixStack,x + 81, y + 34, 176, 0, getProgressWidth(), 12,100);
if (this.menu.breeder.hasChicken1()){
ChickenRenderer.render(matrixStack,x + 19,y + 25, ChickenRegistry.Types.get(this.menu.breeder.getChicken1Name()),minecraft);
//this.itemRenderer.renderAndDecorateItem(this.menu.breeder.getChicken1(),x + 19 , y + 25 );
}
if (this.menu.breeder.hasChicken2()){
ChickenRenderer.render(matrixStack,x + 19,y + 46, ChickenRegistry.Types.get(this.menu.breeder.getChicken2Name()),minecraft);
//this.itemRenderer.renderAndDecorateItem(this.menu.breeder.getChicken2(),x + 19 , y + 46 );
}
}
}

private int getProgressWidth() {
double progress = this.menu.getProgress();
final double progress = this.menu.getProgress();
return progress == 0.0D ? 0 : 1 + (int) (progress * 25);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public void render(@Nonnull MatrixStack p_230430_1_, int p_230430_2_, int p_2304

@Override
protected void renderBg(@Nonnull MatrixStack p_230450_1_, float p_230450_2_, int p_230450_3_, int p_230450_4_) {
RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
assert this.minecraft != null;
this.minecraft.getTextureManager().bind(CONTAINER_BACKGROUND);
int i = (this.width - this.imageWidth) / 2;
int j = (this.height - this.imageHeight) / 2;
this.blit(p_230450_1_, i, j, 0, 0, this.imageWidth, 3 * 18 + 17);
this.blit(p_230450_1_, i, j + 3 * 18 + 17, 0, 126, this.imageWidth, 96);

if (this.minecraft != null) {
RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
this.minecraft.getTextureManager().bind(CONTAINER_BACKGROUND);
int i = (this.width - this.imageWidth) / 2;
int j = (this.height - this.imageHeight) / 2;
this.blit(p_230450_1_, i, j, 0, 0, this.imageWidth, 3 * 18 + 17);
this.blit(p_230450_1_, i, j + 3 * 18 + 17, 0, 126, this.imageWidth, 96);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cn.evolvefield.mods.morechickens.common.entity.BaseChickenEntity;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.IReorderingProcessor;
import net.minecraft.util.ResourceLocation;
Expand Down Expand Up @@ -35,19 +36,20 @@ public RoostScreen(RoostContainer container, PlayerInventory playerInventory, IT
@Override
protected void renderLabels(@NotNull MatrixStack matrixStack, int mouseX, int mouseY) {
drawString(matrixStack,font,new TranslationTextComponent("container.chickens.roost"),4,4,FONT_COLOR);
int x = getGuiLeft();
int y = (height - getYSize()) / 2;
final int x = getGuiLeft();
final int y = (height - getYSize()) / 2;



if (mouseX > x + 69 && mouseX < x + 95 && mouseY > y + 31 && mouseY < y + 46) {
List<IReorderingProcessor> tooltip = new ArrayList<>();
final List<IReorderingProcessor> tooltip = new ArrayList<>();
tooltip.add(new StringTextComponent(this.menu.getFormattedProgress()).getVisualOrderText());
renderTooltip(matrixStack, tooltip, mouseX - x, mouseY - y);
}
if (mouseX > x + 31 && mouseX < x + 49 && mouseY > y + 32 && mouseY < y + 50) {
List<IReorderingProcessor> tooltip = new ArrayList<>();
tooltip.add(new TranslationTextComponent("text.chickens.name."+((BaseChickenEntity)this.menu.tileRoost.getChickenEntity()).getChickenName()).getVisualOrderText());
final List<IReorderingProcessor> tooltip = new ArrayList<>();
final AnimalEntity a = this.menu.tileRoost.getChickenEntity();
if (a!=null) tooltip.add(new TranslationTextComponent("text.chickens.name."+((BaseChickenEntity)a).getChickenName()).getVisualOrderText());
renderTooltip(matrixStack, tooltip, mouseX - x, mouseY - y);
}

Expand All @@ -59,9 +61,8 @@ protected void renderBg(@NotNull MatrixStack matrixStack, float partialTicks, in
if (this.minecraft != null){
RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
this.minecraft.getTextureManager().bind(BACKGROUND);

int x = getGuiLeft();
int y = (height - getYSize()) / 2;
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);
if (this.menu.tileRoost.hasChickenItem()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

public class ScreenBase<T extends Container> extends ContainerScreen<T> {
public static final int FONT_COLOR = 4210752;
protected ResourceLocation texture;
protected List<HoverArea> hoverAreas;
protected final ResourceLocation texture;
protected final List<HoverArea> hoverAreas;

public ScreenBase(ResourceLocation texture, T container, PlayerInventory playerInventory, ITextComponent title) {
super(container, playerInventory, title);
Expand All @@ -34,10 +34,11 @@ public void render(@Nonnull MatrixStack matrixStack, int x, int y, float partial
}

protected void renderBg(@Nonnull MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) {
RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
assert this.minecraft != null;
this.minecraft.getTextureManager().bind(this.texture);
this.blit(matrixStack, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight);
if (this.minecraft != null) {
RenderSystem.clearColor(1.0F, 1.0F, 1.0F, 1.0F);
this.minecraft.getTextureManager().bind(this.texture);
this.blit(matrixStack, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight);
}
}

protected void renderLabels(@Nonnull MatrixStack matrixStack, int mouseX, int mouseY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class BreederContainer extends ContainerBase {
private int progress;
private final IIntArray data;
private static final DecimalFormat FORMATTER = new DecimalFormat("0.0%");
public BreederTileEntity breeder;
public final BreederTileEntity breeder;

public BreederContainer(@Nullable ContainerType<?> containerType, int id, IInventory playerInventory, IInventory inputInventory, IInventory outputInventory, IIntArray data,BreederTileEntity tileEntity) {
super(ModContainers.BREEDER_CONTAINER, id, playerInventory, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class ContainerBase extends Container {
@Nullable
protected IInventory inventory;
protected IInventory playerInventory;

public ContainerBase(@Nullable ContainerType<?> containerType, int id, IInventory playerInventory, IInventory inventory) {
public ContainerBase(@Nullable ContainerType<?> containerType, int id, IInventory playerInventory, @Nonnull IInventory inventory) {
super(containerType, id);
this.playerInventory = playerInventory;
this.inventory = inventory;
Expand Down Expand Up @@ -60,12 +61,13 @@ public IInventory getPlayerInventory() {
return this.playerInventory;
}

@Nonnull
@Override
public ItemStack quickMoveStack(PlayerEntity playerIn, int index) {
public ItemStack quickMoveStack(@Nonnull PlayerEntity playerIn, int index) {
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.slots.get(index);
if (slot != null && slot.hasItem()) {
ItemStack stack = slot.getItem();
final ItemStack stack = slot.getItem();
itemstack = stack.copy();
if (index < this.getInventorySize()) {
if (!this.moveItemStackTo(stack, this.getInventorySize(), this.slots.size(), true)) {
Expand All @@ -86,12 +88,12 @@ public ItemStack quickMoveStack(PlayerEntity playerIn, int index) {
}

@Override
public boolean stillValid(PlayerEntity player) {
return this.inventory == null ? true : this.inventory.stillValid(player);
public boolean stillValid(@Nonnull PlayerEntity player) {
return this.inventory == null || this.inventory.stillValid(player);
}

@Override
public void removed(PlayerEntity player) {
public void removed(@Nonnull PlayerEntity player) {
super.removed(player);
if (this.inventory != null) {
this.inventory.stopOpen(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.function.Function;

public class ItemListInventory implements IInventory, ISidedInventory {
protected NonNullList<ItemStack> items;
protected final NonNullList<ItemStack> items;
private final Runnable onMarkDirty;
private final Function<PlayerEntity, Boolean> onIsUsableByPlayer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

public class ChickenData {

public String name;
public final String name;
//common
public String layItem;
public String deathItem;
public int deathAmount;
public int layAmount;
public int layTime;
//gene
public int GAIN;
public int GROWTH;
public int STRENGTH;
public final int GAIN;
public final int GROWTH;
public final int STRENGTH;

public boolean enabled;
public String parent1, parent2;
protected double weight;
public Pair<String, String> parents;
protected final double weight;
public final Pair<String, String> parents;
public int tier;

public ChickenData(String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ActionResultType interactLivingEntity(@Nonnull ItemStack stack, PlayerEnt
new TranslationTextComponent("text." + MoreChickens.MODID + ".stat.strength", gene.STRENGTH).withStyle(TextFormatting.AQUA),
Util.NIL_UUID);
playerIn.sendMessage(
new TranslationTextComponent("text." + MoreChickens.MODID + ".stat.eggTimer", chickenEntity.getLayTimer() / 1200f).withStyle(TextFormatting.BLACK),
new TranslationTextComponent("text." + MoreChickens.MODID + ".stat.eggTimer", String.format("%.2f",chickenEntity.getLayTimer() / 1200d)).withStyle(TextFormatting.LIGHT_PURPLE),
Util.NIL_UUID);
return ActionResultType.PASS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class RoostTileEntity extends FakeWorldTileEntity implements ITickableTil


private ItemStack chickenItem;
public NonNullList<ItemStack> outputInventory;
public final NonNullList<ItemStack> outputInventory;
private AnimalEntity chickenEntity;
final Random rand = new Random();
private int progress;
Expand Down Expand Up @@ -135,6 +135,7 @@ public boolean hasChickenItem() {
return !chickenItem.isEmpty();
}

@Nullable
public AnimalEntity getChickenEntity() {
if (chickenEntity == null && !chickenItem.isEmpty()) {
chickenEntity = getChicken(level, chickenItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static boolean areItemStackTagsEqual(ItemStack stackA, ItemStack stackB)

public static class ItemHandler extends ItemStackHandler
{
protected TileEntity tileEntity;
protected final TileEntity tileEntity;

public ItemHandler(int size) {
this(size, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/
public class UnorderedPair<T> {

public T first, second;
public final T first;
public final T second;

public UnorderedPair(T a, T b){
first = a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
public class ModBlocks {

public static Block[] BAITS;
public static Block BLOCK_ROOST = new RoostBlock();
public static Block BLOCK_BREEDER = new BreederBlock();
public static Block BLOCK_COLLECTOR = new CollectorBlock();
public static final Block BLOCK_ROOST = new RoostBlock();
public static final Block BLOCK_BREEDER = new BreederBlock();
public static final Block BLOCK_COLLECTOR = new CollectorBlock();


public static void registerBlocks(RegistryEvent.Register<Block> event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ public static class ChickenTypeConfig {
public ForgeConfigSpec.BooleanValue enabled;
}

public Map<String, ChickenTypeConfig> chickenType;
public ForgeConfigSpec.DoubleValue[] tierOdds;

public ForgeConfigSpec.IntValue chickenEggChance, chickenEggMultiChance,
chickenWeight, chickenMin, chickenMax, chickenBreedingTime;
public final Map<String, ChickenTypeConfig> chickenType;
public final ForgeConfigSpec.DoubleValue[] tierOdds;

public final ForgeConfigSpec.IntValue chickenEggChance;
public final ForgeConfigSpec.IntValue chickenEggMultiChance;
public final ForgeConfigSpec.IntValue chickenWeight;
public final ForgeConfigSpec.IntValue chickenMin;
public final ForgeConfigSpec.IntValue chickenMax;
public final ForgeConfigSpec.IntValue chickenBreedingTime;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class ModItems {
public static Item GRAY_EGG;
public static Item BROWN_EGG;

public static Item ITEM_CHICKEN = new ChickenItem();
public static Item ITEM_CATCHER = new CatcherItem();
public static Item ANALYZER = new AnalyzerItem();
public static final Item ITEM_CHICKEN = new ChickenItem();
public static final Item ITEM_CATCHER = new CatcherItem();
public static final Item ANALYZER = new AnalyzerItem();

public static void registerItems(RegistryEvent.Register<Item> event) {
final IForgeRegistry<Item> registry = event.getRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public ResourceLocation getPluginUid() {

@Override
public void registerRecipes(@Nonnull IRecipeRegistration registration) {
assert Minecraft.getInstance().level != null;
final RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager();
final World clientWorld = Minecraft.getInstance().level;
if (clientWorld != null) {
registration.addRecipes(BreederCategory.getBreedingRecipes(), BreederCategory.ID);
registerInfoDesc(registration);
if (Minecraft.getInstance().level != null) {
final RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager();
final World clientWorld = Minecraft.getInstance().level;
if (clientWorld != null) {
registration.addRecipes(BreederCategory.getBreedingRecipes(), BreederCategory.ID);
registerInfoDesc(registration);
}
}

}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "${file.jarVersion}" #mandatory
displayName = "MoreChickens" #mandatory
logoFile="chickens_logo.png" #optional

authors = "cnlimiter" #optional
authors = "cnlimiter, Tapio" #optional
description = '''
A mod extend Chickens
'''
Expand Down

0 comments on commit a368209

Please sign in to comment.