Code style changes, entities fixes
This commit is contained in:
parent
9d604b2d25
commit
44962e18b6
377 changed files with 5038 additions and 4914 deletions
|
@ -47,11 +47,11 @@ import java.util.Map;
|
|||
|
||||
public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder, StackedContentsCompatible {
|
||||
|
||||
private static final int[] TOP_SLOTS = new int[] { 0, 1 };
|
||||
private static final int[] BOTTOM_SLOTS = new int[] { 2, 3 };
|
||||
private static final int[] SIDE_SLOTS = new int[] { 1, 2 };
|
||||
private static final int[] TOP_SLOTS = new int[]{0, 1};
|
||||
private static final int[] BOTTOM_SLOTS = new int[]{2, 3};
|
||||
private static final int[] SIDE_SLOTS = new int[]{1, 2};
|
||||
private static final Map<Item, Integer> AVAILABLE_FUELS = Maps.newHashMap();
|
||||
|
||||
|
||||
private final Object2IntOpenHashMap<ResourceLocation> recipesUsed;
|
||||
protected NonNullList<ItemStack> inventory;
|
||||
protected final ContainerData propertyDelegate;
|
||||
|
@ -60,47 +60,47 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
private int smeltTime;
|
||||
private int burnTime;
|
||||
private int fuelTime;
|
||||
|
||||
|
||||
public EndStoneSmelterBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
super(EndBlockEntities.END_STONE_SMELTER, blockPos, blockState);
|
||||
this.inventory = NonNullList.withSize(4, ItemStack.EMPTY);
|
||||
this.recipesUsed = new Object2IntOpenHashMap<>();
|
||||
this.propertyDelegate = new ContainerData() {
|
||||
public int get(int index) {
|
||||
switch(index) {
|
||||
case 0:
|
||||
return EndStoneSmelterBlockEntity.this.burnTime;
|
||||
case 1:
|
||||
return EndStoneSmelterBlockEntity.this.fuelTime;
|
||||
case 2:
|
||||
return EndStoneSmelterBlockEntity.this.smeltTime;
|
||||
case 3:
|
||||
return EndStoneSmelterBlockEntity.this.smeltTimeTotal;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
this.propertyDelegate = new ContainerData() {
|
||||
public int get(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return EndStoneSmelterBlockEntity.this.burnTime;
|
||||
case 1:
|
||||
return EndStoneSmelterBlockEntity.this.fuelTime;
|
||||
case 2:
|
||||
return EndStoneSmelterBlockEntity.this.smeltTime;
|
||||
case 3:
|
||||
return EndStoneSmelterBlockEntity.this.smeltTimeTotal;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int index, int value) {
|
||||
switch(index) {
|
||||
case 0:
|
||||
EndStoneSmelterBlockEntity.this.burnTime = value;
|
||||
break;
|
||||
case 1:
|
||||
EndStoneSmelterBlockEntity.this.fuelTime = value;
|
||||
break;
|
||||
case 2:
|
||||
EndStoneSmelterBlockEntity.this.smeltTime = value;
|
||||
break;
|
||||
case 3:
|
||||
EndStoneSmelterBlockEntity.this.smeltTimeTotal = value;
|
||||
}
|
||||
}
|
||||
public void set(int index, int value) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
EndStoneSmelterBlockEntity.this.burnTime = value;
|
||||
break;
|
||||
case 1:
|
||||
EndStoneSmelterBlockEntity.this.fuelTime = value;
|
||||
break;
|
||||
case 2:
|
||||
EndStoneSmelterBlockEntity.this.smeltTime = value;
|
||||
break;
|
||||
case 3:
|
||||
EndStoneSmelterBlockEntity.this.smeltTimeTotal = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return 4;
|
||||
}
|
||||
};
|
||||
public int getCount() {
|
||||
return 4;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isBurning() {
|
||||
|
@ -121,7 +121,8 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
return true;
|
||||
}
|
||||
itemStack = iterator.next();
|
||||
} while (itemStack.isEmpty());
|
||||
}
|
||||
while (itemStack.isEmpty());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -155,19 +156,19 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected int getSmeltTime() {
|
||||
if (level == null) return 200;
|
||||
int smeltTime = level.getRecipeManager().getRecipeFor(AlloyingRecipe.TYPE, this, level)
|
||||
.map(AlloyingRecipe::getSmeltTime).orElse(0);
|
||||
if (smeltTime == 0) {
|
||||
smeltTime = level.getRecipeManager().getRecipeFor(RecipeType.BLASTING, this, level)
|
||||
.map(BlastingRecipe::getCookingTime).orElse(200);
|
||||
.map(BlastingRecipe::getCookingTime).orElse(200);
|
||||
smeltTime /= 1.5;
|
||||
}
|
||||
return smeltTime;
|
||||
}
|
||||
|
||||
|
||||
public void dropExperience(Player player) {
|
||||
if (level == null) return;
|
||||
List<Recipe<?>> list = Lists.newArrayList();
|
||||
|
@ -177,7 +178,8 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
if (recipe instanceof AlloyingRecipe) {
|
||||
AlloyingRecipe alloying = (AlloyingRecipe) recipe;
|
||||
dropExperience(player.level, player.position(), entry.getIntValue(), alloying.getExperience());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
BlastingRecipe blasting = (BlastingRecipe) recipe;
|
||||
dropExperience(player.level, player.position(), entry.getIntValue(), blasting.getExperience());
|
||||
}
|
||||
|
@ -186,7 +188,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
player.awardRecipes(list);
|
||||
recipesUsed.clear();
|
||||
}
|
||||
|
||||
|
||||
private void dropExperience(Level world, Vec3 vec3d, int count, float amount) {
|
||||
int expTotal = Mth.floor(count * amount);
|
||||
float g = Mth.frac(count * amount);
|
||||
|
@ -194,7 +196,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
expTotal++;
|
||||
}
|
||||
|
||||
while(expTotal > 0) {
|
||||
while (expTotal > 0) {
|
||||
int expVal = ExperienceOrb.getExperienceValue(expTotal);
|
||||
expTotal -= expVal;
|
||||
world.addFreshEntity(new ExperienceOrb(world, vec3d.x, vec3d.y, vec3d.z, expVal));
|
||||
|
@ -239,7 +241,8 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
if (blockEntity.smeltTime > 0) {
|
||||
blockEntity.smeltTime = Mth.clamp(blockEntity.smeltTime - 2, 0, blockEntity.smeltTimeTotal);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Recipe<?> recipe = tickLevel.getRecipeManager().getRecipeFor(AlloyingRecipe.TYPE, blockEntity, tickLevel).orElse(null);
|
||||
if (recipe == null) {
|
||||
recipe = tickLevel.getRecipeManager().getRecipeFor(RecipeType.BLASTING, blockEntity, tickLevel).orElse(null);
|
||||
|
@ -270,7 +273,8 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
blockEntity.craftRecipe(recipe);
|
||||
blockEntity.setChanged();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
blockEntity.smeltTime = 0;
|
||||
}
|
||||
}
|
||||
|
@ -281,14 +285,15 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean canAcceptRecipeOutput(Recipe<?> recipe) {
|
||||
if (recipe == null) return false;
|
||||
boolean validInput;
|
||||
if (recipe instanceof AlloyingRecipe) {
|
||||
validInput = !inventory.get(0).isEmpty() &&
|
||||
!inventory.get(1).isEmpty();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
validInput = !inventory.get(0).isEmpty() ||
|
||||
!inventory.get(1).isEmpty();
|
||||
}
|
||||
|
@ -316,12 +321,13 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
|
||||
private void craftRecipe(Recipe<?> recipe) {
|
||||
if (recipe == null || !canAcceptRecipeOutput(recipe)) return;
|
||||
|
||||
|
||||
ItemStack result = recipe.getResultItem();
|
||||
ItemStack output = inventory.get(3);
|
||||
if (output.isEmpty()) {
|
||||
inventory.set(3, result.copy());
|
||||
} else if (output.getItem() == result.getItem()) {
|
||||
}
|
||||
else if (output.getItem() == result.getItem()) {
|
||||
output.grow(result.getCount());
|
||||
}
|
||||
|
||||
|
@ -329,14 +335,16 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
if (!this.level.isClientSide) {
|
||||
setRecipeUsed(recipe);
|
||||
}
|
||||
|
||||
|
||||
if (recipe instanceof AlloyingRecipe) {
|
||||
inventory.get(0).shrink(1);
|
||||
inventory.get(1).shrink(1);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (!inventory.get(0).isEmpty()) {
|
||||
inventory.get(0).shrink(1);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
inventory.get(1).shrink(1);
|
||||
}
|
||||
}
|
||||
|
@ -391,7 +399,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
Item item = fuel.getItem();
|
||||
return AVAILABLE_FUELS.getOrDefault(item, getFabricFuel(fuel));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void load(CompoundTag tag) {
|
||||
super.load(tag);
|
||||
|
@ -406,7 +414,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
recipesUsed.put(new ResourceLocation(id), compoundTag.getInt(id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompoundTag save(CompoundTag tag) {
|
||||
super.save(tag);
|
||||
|
@ -418,14 +426,15 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
CompoundTag usedRecipes = new CompoundTag();
|
||||
recipesUsed.forEach((identifier, integer) -> usedRecipes.putInt(identifier.toString(), integer));
|
||||
tag.put("RecipesUsed", usedRecipes);
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
public boolean canPlaceItem(int slot, ItemStack stack) {
|
||||
if (slot == 3) {
|
||||
return false;
|
||||
} else if (slot != 2) {
|
||||
}
|
||||
else if (slot != 2) {
|
||||
return true;
|
||||
}
|
||||
ItemStack itemStack = this.inventory.get(2);
|
||||
|
@ -443,7 +452,7 @@ public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity impleme
|
|||
public static Map<Item, Integer> availableFuels() {
|
||||
return AVAILABLE_FUELS;
|
||||
}
|
||||
|
||||
|
||||
private static int getFabricFuel(ItemStack stack) {
|
||||
Integer ticks = FuelRegistry.INSTANCE.get(stack.getItem());
|
||||
return ticks == null ? 0 : ticks;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue