End Stone Smelter slots fix
This commit is contained in:
parent
c3277e7a2e
commit
e991a8a23a
1 changed files with 40 additions and 67 deletions
|
@ -1,15 +1,9 @@
|
||||||
package ru.betterend.blocks.entities;
|
package ru.betterend.blocks.entities;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
|
import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
import net.minecraft.block.entity.LockableContainerBlockEntity;
|
||||||
|
@ -23,15 +17,9 @@ import net.minecraft.item.ItemConvertible;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.recipe.BlastingRecipe;
|
import net.minecraft.recipe.*;
|
||||||
import net.minecraft.recipe.Recipe;
|
|
||||||
import net.minecraft.recipe.RecipeFinder;
|
|
||||||
import net.minecraft.recipe.RecipeInputProvider;
|
|
||||||
import net.minecraft.recipe.RecipeType;
|
|
||||||
import net.minecraft.recipe.RecipeUnlocker;
|
|
||||||
import net.minecraft.screen.PropertyDelegate;
|
import net.minecraft.screen.PropertyDelegate;
|
||||||
import net.minecraft.screen.ScreenHandler;
|
import net.minecraft.screen.ScreenHandler;
|
||||||
import net.minecraft.tag.Tag;
|
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
@ -47,11 +35,15 @@ import ru.betterend.client.gui.EndStoneSmelterScreenHandler;
|
||||||
import ru.betterend.recipe.builders.AlloyingRecipe;
|
import ru.betterend.recipe.builders.AlloyingRecipe;
|
||||||
import ru.betterend.registry.EndBlockEntities;
|
import ru.betterend.registry.EndBlockEntities;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity implements SidedInventory, RecipeUnlocker, RecipeInputProvider, Tickable {
|
public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity implements SidedInventory, RecipeUnlocker, RecipeInputProvider, Tickable {
|
||||||
|
|
||||||
private static final int[] TOP_SLOTS = new int[] { 0, 1 };
|
private static final int[] TOP_SLOTS = new int[] { 0, 1 };
|
||||||
private static final int[] BOTTOM_SLOTS = new int[] { 2, 3 };
|
private static final int[] BOTTOM_SLOTS = new int[] { 2, 3 };
|
||||||
private static final int[] SIDE_SLOTS = new int[] { 3 };
|
private static final int[] SIDE_SLOTS = new int[] { 1, 2 };
|
||||||
private static final Map<Item, Integer> AVAILABLE_FUELS = Maps.newHashMap();
|
private static final Map<Item, Integer> AVAILABLE_FUELS = Maps.newHashMap();
|
||||||
|
|
||||||
private final Object2IntOpenHashMap<Identifier> recipesUsed;
|
private final Object2IntOpenHashMap<Identifier> recipesUsed;
|
||||||
|
@ -66,7 +58,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
public EndStoneSmelterBlockEntity() {
|
public EndStoneSmelterBlockEntity() {
|
||||||
super(EndBlockEntities.END_STONE_SMELTER);
|
super(EndBlockEntities.END_STONE_SMELTER);
|
||||||
this.inventory = DefaultedList.ofSize(4, ItemStack.EMPTY);
|
this.inventory = DefaultedList.ofSize(4, ItemStack.EMPTY);
|
||||||
this.recipesUsed = new Object2IntOpenHashMap<Identifier>();
|
this.recipesUsed = new Object2IntOpenHashMap<>();
|
||||||
this.propertyDelegate = new PropertyDelegate() {
|
this.propertyDelegate = new PropertyDelegate() {
|
||||||
public int get(int index) {
|
public int get(int index) {
|
||||||
switch(index) {
|
switch(index) {
|
||||||
|
@ -167,6 +159,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getSmeltTime() {
|
protected int getSmeltTime() {
|
||||||
|
assert this.world != null;
|
||||||
int smeltTime = this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, this, world)
|
int smeltTime = this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, this, world)
|
||||||
.map(AlloyingRecipe::getSmeltTime).orElse(0);
|
.map(AlloyingRecipe::getSmeltTime).orElse(0);
|
||||||
if (smeltTime == 0) {
|
if (smeltTime == 0) {
|
||||||
|
@ -178,10 +171,9 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropExperience(PlayerEntity player) {
|
public void dropExperience(PlayerEntity player) {
|
||||||
|
assert world != null;
|
||||||
List<Recipe<?>> list = Lists.newArrayList();
|
List<Recipe<?>> list = Lists.newArrayList();
|
||||||
ObjectIterator<Entry<Identifier>> usedRecipes = this.recipesUsed.object2IntEntrySet().iterator();
|
for (Entry<Identifier> entry : this.recipesUsed.object2IntEntrySet()) {
|
||||||
while(usedRecipes.hasNext()) {
|
|
||||||
Entry<Identifier> entry = usedRecipes.next();
|
|
||||||
world.getRecipeManager().get(entry.getKey()).ifPresent((recipe) -> {
|
world.getRecipeManager().get(entry.getKey()).ifPresent((recipe) -> {
|
||||||
list.add(recipe);
|
list.add(recipe);
|
||||||
if (recipe instanceof AlloyingRecipe) {
|
if (recipe instanceof AlloyingRecipe) {
|
||||||
|
@ -213,11 +205,11 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlayerUse(PlayerEntity player) {
|
public boolean canPlayerUse(PlayerEntity player) {
|
||||||
|
assert this.world != null;
|
||||||
if (this.world.getBlockEntity(this.pos) != this) {
|
if (this.world.getBlockEntity(this.pos) != this) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
return player.squaredDistanceTo(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64.0D;
|
|
||||||
}
|
}
|
||||||
|
return player.squaredDistanceTo(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -243,10 +235,11 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean burning = this.isBurning();
|
boolean burning = this.isBurning();
|
||||||
|
assert this.world != null;
|
||||||
if (!this.world.isClient) {
|
if (!this.world.isClient) {
|
||||||
ItemStack fuel = this.inventory.get(2);
|
ItemStack fuel = this.inventory.get(2);
|
||||||
if (!burning && (fuel.isEmpty() || inventory.get(0).isEmpty() && inventory.get(1).isEmpty())) {
|
if (!burning && (fuel.isEmpty() || inventory.get(0).isEmpty() && inventory.get(1).isEmpty())) {
|
||||||
if (!burning && smeltTime > 0) {
|
if (smeltTime > 0) {
|
||||||
this.smeltTime = MathHelper.clamp(smeltTime - 2, 0, smeltTimeTotal);
|
this.smeltTime = MathHelper.clamp(smeltTime - 2, 0, smeltTimeTotal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -294,7 +287,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
|
|
||||||
protected boolean canAcceptRecipeOutput(Recipe<?> recipe) {
|
protected boolean canAcceptRecipeOutput(Recipe<?> recipe) {
|
||||||
if (recipe == null) return false;
|
if (recipe == null) return false;
|
||||||
boolean validInput = false;
|
boolean validInput;
|
||||||
if (recipe instanceof AlloyingRecipe) {
|
if (recipe instanceof AlloyingRecipe) {
|
||||||
validInput = !inventory.get(0).isEmpty() &&
|
validInput = !inventory.get(0).isEmpty() &&
|
||||||
!inventory.get(1).isEmpty();
|
!inventory.get(1).isEmpty();
|
||||||
|
@ -306,22 +299,21 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
ItemStack result = recipe.getOutput();
|
ItemStack result = recipe.getOutput();
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
ItemStack output = this.inventory.get(3);
|
ItemStack output = this.inventory.get(3);
|
||||||
int outCount = output.getCount();
|
int outCount = output.getCount();
|
||||||
int total = outCount + result.getCount();
|
int total = outCount + result.getCount();
|
||||||
if (output.isEmpty()) {
|
if (output.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (!output.isItemEqualIgnoreDamage(result)) {
|
}
|
||||||
|
if (!output.isItemEqualIgnoreDamage(result)) {
|
||||||
return false;
|
return false;
|
||||||
} else if (outCount < this.getMaxCountPerStack() && outCount < output.getMaxCount()) {
|
}
|
||||||
|
if (outCount < this.getMaxCountPerStack() && outCount < output.getMaxCount()) {
|
||||||
return this.getMaxCountPerStack() >= total;
|
return this.getMaxCountPerStack() >= total;
|
||||||
} else {
|
}
|
||||||
return output.getCount() < result.getMaxCount();
|
return output.getCount() < result.getMaxCount();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,6 +328,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
output.increment(result.getCount());
|
output.increment(result.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert this.world != null;
|
||||||
if (!this.world.isClient) {
|
if (!this.world.isClient) {
|
||||||
this.setLastRecipe(recipe);
|
this.setLastRecipe(recipe);
|
||||||
}
|
}
|
||||||
|
@ -354,9 +347,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provideRecipeInputs(RecipeFinder finder) {
|
public void provideRecipeInputs(RecipeFinder finder) {
|
||||||
Iterator<ItemStack> inventory = this.inventory.iterator();
|
for (ItemStack itemStack : this.inventory) {
|
||||||
while(inventory.hasNext()) {
|
|
||||||
ItemStack itemStack = inventory.next();
|
|
||||||
finder.addItem(itemStack);
|
finder.addItem(itemStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,9 +370,8 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
public int[] getAvailableSlots(Direction side) {
|
public int[] getAvailableSlots(Direction side) {
|
||||||
if (side == Direction.DOWN) {
|
if (side == Direction.DOWN) {
|
||||||
return BOTTOM_SLOTS;
|
return BOTTOM_SLOTS;
|
||||||
} else {
|
|
||||||
return side == Direction.UP ? TOP_SLOTS : SIDE_SLOTS;
|
|
||||||
}
|
}
|
||||||
|
return side == Direction.UP ? TOP_SLOTS : SIDE_SLOTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -392,9 +382,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtract(int slot, ItemStack stack, Direction dir) {
|
public boolean canExtract(int slot, ItemStack stack, Direction dir) {
|
||||||
if (dir == Direction.DOWN && slot == 2) {
|
if (dir == Direction.DOWN && slot == 2) {
|
||||||
if (stack.getItem() != Items.BUCKET) {
|
return stack.getItem() == Items.BUCKET;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -402,11 +390,10 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
protected int getFuelTime(ItemStack fuel) {
|
protected int getFuelTime(ItemStack fuel) {
|
||||||
if (fuel.isEmpty()) {
|
if (fuel.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
}
|
||||||
Item item = fuel.getItem();
|
Item item = fuel.getItem();
|
||||||
return AVAILABLE_FUELS.getOrDefault(item, 0);
|
return AVAILABLE_FUELS.getOrDefault(item, 0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromTag(BlockState state, CompoundTag tag) {
|
public void fromTag(BlockState state, CompoundTag tag) {
|
||||||
|
@ -418,9 +405,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
this.smeltTime = tag.getShort("SmeltTime");
|
this.smeltTime = tag.getShort("SmeltTime");
|
||||||
this.smeltTimeTotal = tag.getShort("SmeltTimeTotal");
|
this.smeltTimeTotal = tag.getShort("SmeltTimeTotal");
|
||||||
CompoundTag compoundTag = tag.getCompound("RecipesUsed");
|
CompoundTag compoundTag = tag.getCompound("RecipesUsed");
|
||||||
Iterator<String> recipes = compoundTag.getKeys().iterator();
|
for (String id : compoundTag.getKeys()) {
|
||||||
while(recipes.hasNext()) {
|
|
||||||
String id = recipes.next();
|
|
||||||
this.recipesUsed.put(new Identifier(id), compoundTag.getInt(id));
|
this.recipesUsed.put(new Identifier(id), compoundTag.getInt(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -434,9 +419,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
tag.putShort("SmeltTimeTotal", (short) smeltTimeTotal);
|
tag.putShort("SmeltTimeTotal", (short) smeltTimeTotal);
|
||||||
Inventories.toTag(tag, inventory);
|
Inventories.toTag(tag, inventory);
|
||||||
CompoundTag usedRecipes = new CompoundTag();
|
CompoundTag usedRecipes = new CompoundTag();
|
||||||
this.recipesUsed.forEach((identifier, integer) -> {
|
this.recipesUsed.forEach((identifier, integer) -> usedRecipes.putInt(identifier.toString(), integer));
|
||||||
usedRecipes.putInt(identifier.toString(), integer);
|
|
||||||
});
|
|
||||||
tag.put("RecipesUsed", usedRecipes);
|
tag.put("RecipesUsed", usedRecipes);
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
|
@ -445,30 +428,20 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
|
||||||
public boolean isValid(int slot, ItemStack stack) {
|
public boolean isValid(int slot, ItemStack stack) {
|
||||||
if (slot == 3) {
|
if (slot == 3) {
|
||||||
return false;
|
return false;
|
||||||
} else if (slot != 0 || slot != 1) {
|
} else if (slot != 2) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
ItemStack itemStack = this.inventory.get(2);
|
ItemStack itemStack = this.inventory.get(2);
|
||||||
return canUseAsFuel(stack) || stack.getItem() == Items.BUCKET && itemStack.getItem() != Items.BUCKET;
|
return canUseAsFuel(stack) || stack.getItem() == Items.BUCKET && itemStack.getItem() != Items.BUCKET;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean canUseAsFuel(ItemStack stack) {
|
public static boolean canUseAsFuel(ItemStack stack) {
|
||||||
return AVAILABLE_FUELS.containsKey(stack.getItem());
|
return AVAILABLE_FUELS.containsKey(stack.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerFuel(ItemConvertible fuel, int time) {
|
public static void registerFuel(ItemConvertible fuel, int time) {
|
||||||
if (AVAILABLE_FUELS.containsKey(fuel)) {
|
|
||||||
AVAILABLE_FUELS.replace(fuel.asItem(), time);
|
|
||||||
} else {
|
|
||||||
AVAILABLE_FUELS.put(fuel.asItem(), time);
|
AVAILABLE_FUELS.put(fuel.asItem(), time);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerFuel(Tag<Item> tag, int time) {
|
|
||||||
Iterator<Item> tagItems = tag.values().iterator();
|
|
||||||
tagItems.forEachRemaining(item -> registerFuel(item, time));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<Item, Integer> availableFuels() {
|
public static Map<Item, Integer> availableFuels() {
|
||||||
return AVAILABLE_FUELS;
|
return AVAILABLE_FUELS;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue