Continue mapping migration
This commit is contained in:
parent
99ade39404
commit
f03fd03bd0
499 changed files with 12567 additions and 12723 deletions
|
@ -1,31 +1,32 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.TickableBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.betterend.blocks.HydrothermalVentBlock;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndParticles;
|
||||
|
||||
public class BlockEntityHydrothermalVent extends BlockEntity implements Tickable {
|
||||
public class BlockEntityHydrothermalVent extends BlockEntity implements TickableBlockEntity {
|
||||
public BlockEntityHydrothermalVent() {
|
||||
super(EndBlockEntities.HYDROTHERMAL_VENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (world.random.nextInt(20) == 0) {
|
||||
double x = pos.getX() + world.random.nextDouble();
|
||||
double y = pos.getY() + 0.9 + world.random.nextDouble() * 0.3;
|
||||
double z = pos.getZ() + world.random.nextDouble();
|
||||
BlockState state = getCachedState();
|
||||
if (level.random.nextInt(20) == 0) {
|
||||
double x = worldPosition.getX() + level.random.nextDouble();
|
||||
double y = worldPosition.getY() + 0.9 + level.random.nextDouble() * 0.3;
|
||||
double z = worldPosition.getZ() + level.random.nextDouble();
|
||||
BlockState state = getBlockState();
|
||||
if (state.is(EndBlocks.HYDROTHERMAL_VENT) && state.getValue(HydrothermalVentBlock.ACTIVATED)) {
|
||||
if (state.getValue(HydrothermalVentBlock.WATERLOGGED)) {
|
||||
world.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0);
|
||||
} else {
|
||||
world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0);
|
||||
level.addParticle(EndParticles.GEYSER_PARTICLE, x, y, z, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
level.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,89 +1,89 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.world.level.block.BarrelBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventories;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ChestMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.BarrelBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.betterend.blocks.basis.EndBarrelBlock;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EBarrelBlockEntity extends LootableContainerBlockEntity {
|
||||
private DefaultedList<ItemStack> inventory;
|
||||
public class EBarrelBlockEntity extends RandomizableContainerBlockEntity {
|
||||
private NonNullList<ItemStack> inventory;
|
||||
private int viewerCount;
|
||||
|
||||
private EBarrelBlockEntity(BlockEntityType<?> type) {
|
||||
super(type);
|
||||
this.inventory = DefaultedList.ofSize(27, ItemStack.EMPTY);
|
||||
this.inventory = NonNullList.withSize(27, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public EBarrelBlockEntity() {
|
||||
this(EndBlockEntities.BARREL);
|
||||
}
|
||||
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
if (!this.serializeLootTable(tag)) {
|
||||
Inventories.toTag(tag, this.inventory);
|
||||
public CompoundTag save(CompoundTag tag) {
|
||||
super.save(tag);
|
||||
if (!this.trySaveLootTable(tag)) {
|
||||
ContainerHelper.saveAllItems(tag, this.inventory);
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
this.inventory = DefaultedList.ofSize(this.size(), ItemStack.EMPTY);
|
||||
if (!this.deserializeLootTable(tag)) {
|
||||
Inventories.fromTag(tag, this.inventory);
|
||||
public void load(BlockState state, CompoundTag tag) {
|
||||
super.load(state, tag);
|
||||
this.inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
|
||||
if (!this.tryLoadLootTable(tag)) {
|
||||
ContainerHelper.loadAllItems(tag, this.inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
public int getContainerSize() {
|
||||
return 27;
|
||||
}
|
||||
|
||||
protected DefaultedList<ItemStack> getInvStackList() {
|
||||
protected NonNullList<ItemStack> getItems() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
protected void setInvStackList(DefaultedList<ItemStack> list) {
|
||||
protected void setItems(NonNullList<ItemStack> list) {
|
||||
this.inventory = list;
|
||||
}
|
||||
|
||||
protected Text getContainerName() {
|
||||
return new TranslatableText("container.barrel");
|
||||
protected Component getDefaultName() {
|
||||
return new TranslatableComponent("container.barrel");
|
||||
}
|
||||
|
||||
protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
return GenericContainerScreenHandler.createGeneric9x3(syncId, playerInventory, this);
|
||||
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
|
||||
return ChestMenu.threeRows(syncId, playerInventory, this);
|
||||
}
|
||||
|
||||
public void onOpen(Player player) {
|
||||
public void startOpen(Player player) {
|
||||
if (!player.isSpectator()) {
|
||||
if (this.viewerCount < 0) {
|
||||
this.viewerCount = 0;
|
||||
}
|
||||
|
||||
++this.viewerCount;
|
||||
BlockState blockState = this.getCachedState();
|
||||
boolean bl = (Boolean) blockState.get(BarrelBlock.OPEN);
|
||||
BlockState blockState = this.getBlockState();
|
||||
boolean bl = (Boolean) blockState.getValue(BarrelBlock.OPEN);
|
||||
if (!bl) {
|
||||
this.playSound(blockState, SoundEvents.BLOCK_BARREL_OPEN);
|
||||
this.playSound(blockState, SoundEvents.BARREL_OPEN);
|
||||
this.setOpen(blockState, true);
|
||||
}
|
||||
|
||||
|
@ -92,47 +92,47 @@ public class EBarrelBlockEntity extends LootableContainerBlockEntity {
|
|||
}
|
||||
|
||||
private void scheduleUpdate() {
|
||||
this.world.getBlockTickScheduler().schedule(this.getPos(), this.getCachedState().getBlock(), 5);
|
||||
this.level.getBlockTicks().scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), 5);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
int i = this.pos.getX();
|
||||
int j = this.pos.getY();
|
||||
int k = this.pos.getZ();
|
||||
this.viewerCount = ChestBlockEntity.countViewers(this.world, this, i, j, k);
|
||||
int i = this.worldPosition.getX();
|
||||
int j = this.worldPosition.getY();
|
||||
int k = this.worldPosition.getZ();
|
||||
this.viewerCount = ChestBlockEntity.getOpenCount(this.level, this, i, j, k);
|
||||
if (this.viewerCount > 0) {
|
||||
this.scheduleUpdate();
|
||||
} else {
|
||||
BlockState blockState = this.getCachedState();
|
||||
BlockState blockState = this.getBlockState();
|
||||
if (!(blockState.getBlock() instanceof EndBarrelBlock)) {
|
||||
this.markRemoved();
|
||||
this.setRemoved();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean bl = (Boolean) blockState.get(BarrelBlock.OPEN);
|
||||
boolean bl = (Boolean) blockState.getValue(BarrelBlock.OPEN);
|
||||
if (bl) {
|
||||
this.playSound(blockState, SoundEvents.BLOCK_BARREL_CLOSE);
|
||||
this.playSound(blockState, SoundEvents.BARREL_CLOSE);
|
||||
this.setOpen(blockState, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onClose(Player player) {
|
||||
public void stopOpen(Player player) {
|
||||
if (!player.isSpectator()) {
|
||||
--this.viewerCount;
|
||||
}
|
||||
}
|
||||
|
||||
private void setOpen(BlockState state, boolean open) {
|
||||
this.world.setBlockAndUpdate(this.getPos(), (BlockState) state.with(BarrelBlock.OPEN, open), 3);
|
||||
this.level.setBlock(this.getBlockPos(), (BlockState) state.setValue(BarrelBlock.OPEN, open), 3);
|
||||
}
|
||||
|
||||
private void playSound(BlockState blockState, SoundEvent soundEvent) {
|
||||
Vec3i vec3i = ((Direction) blockState.get(BarrelBlock.FACING)).getVector();
|
||||
double d = (double) this.pos.getX() + 0.5D + (double) vec3i.getX() / 2.0D;
|
||||
double e = (double) this.pos.getY() + 0.5D + (double) vec3i.getY() / 2.0D;
|
||||
double f = (double) this.pos.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D;
|
||||
this.world.playLocalSound((Player) null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F,
|
||||
this.world.random.nextFloat() * 0.1F + 0.9F);
|
||||
Vec3i vec3i = ((Direction) blockState.getValue(BarrelBlock.FACING)).getNormal();
|
||||
double d = (double) this.worldPosition.getX() + 0.5D + (double) vec3i.getX() / 2.0D;
|
||||
double e = (double) this.worldPosition.getY() + 0.5D + (double) vec3i.getY() / 2.0D;
|
||||
double f = (double) this.worldPosition.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D;
|
||||
this.level.playSound((Player) null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F,
|
||||
this.level.random.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.world.entity.player.PlayerInventory;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.FurnaceMenu;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.screen.FurnaceScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EFurnaceBlockEntity extends AbstractFurnaceBlockEntity {
|
||||
|
@ -14,11 +14,11 @@ public class EFurnaceBlockEntity extends AbstractFurnaceBlockEntity {
|
|||
super(EndBlockEntities.FURNACE, RecipeType.SMELTING);
|
||||
}
|
||||
|
||||
protected Text getContainerName() {
|
||||
return new TranslatableText("container.furnace");
|
||||
protected Component getDefaultName() {
|
||||
return new TranslatableComponent("container.furnace");
|
||||
}
|
||||
|
||||
protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
return new FurnaceScreenHandler(syncId, playerInventory, this, this.propertyDelegate);
|
||||
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
|
||||
return new FurnaceMenu(syncId, playerInventory, this, this.dataAccess);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,99 +10,98 @@ import com.google.common.collect.Maps;
|
|||
import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import net.fabricmc.fabric.api.registry.FuelRegistry;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.LockableContainerBlockEntity;
|
||||
import net.minecraft.world.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.WorldlyContainer;
|
||||
import net.minecraft.world.entity.ExperienceOrb;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventories;
|
||||
import net.minecraft.inventory.SidedInventory;
|
||||
import net.minecraft.world.entity.player.StackedContents;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ContainerData;
|
||||
import net.minecraft.world.inventory.RecipeHolder;
|
||||
import net.minecraft.world.inventory.StackedContentsCompatible;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.crafting.BlastingRecipe;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeFinder;
|
||||
import net.minecraft.world.item.crafting.RecipeInputProvider;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.item.crafting.RecipeUnlocker;
|
||||
import net.minecraft.screen.PropertyDelegate;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.TickableBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.EndStoneSmelter;
|
||||
import ru.betterend.client.gui.EndStoneSmelterScreenHandler;
|
||||
import ru.betterend.recipe.builders.AlloyingRecipe;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
|
||||
public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
||||
implements SidedInventory, RecipeUnlocker, RecipeInputProvider, Tickable {
|
||||
public class EndStoneSmelterBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeHolder, StackedContentsCompatible, TickableBlockEntity {
|
||||
|
||||
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 DefaultedList<ItemStack> inventory;
|
||||
protected final PropertyDelegate propertyDelegate;
|
||||
protected NonNullList<ItemStack> inventory;
|
||||
protected final ContainerData propertyDelegate;
|
||||
private Recipe<?> lastRecipe;
|
||||
private int smeltTimeTotal;
|
||||
private int smeltTime;
|
||||
private int burnTime;
|
||||
private int fuelTime;
|
||||
|
||||
|
||||
public EndStoneSmelterBlockEntity() {
|
||||
super(EndBlockEntities.END_STONE_SMELTER);
|
||||
this.inventory = DefaultedList.ofSize(4, ItemStack.EMPTY);
|
||||
this.inventory = NonNullList.withSize(4, ItemStack.EMPTY);
|
||||
this.recipesUsed = new Object2IntOpenHashMap<>();
|
||||
this.propertyDelegate = new PropertyDelegate() {
|
||||
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 size() {
|
||||
return 4;
|
||||
}
|
||||
};
|
||||
public int getCount() {
|
||||
return 4;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isBurning() {
|
||||
|
@ -110,7 +109,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
public int getContainerSize() {
|
||||
return this.inventory.size();
|
||||
}
|
||||
|
||||
|
@ -129,103 +128,101 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack(int slot) {
|
||||
public ItemStack getItem(int slot) {
|
||||
return this.inventory.get(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot, int amount) {
|
||||
return Inventories.splitStack(this.inventory, slot, amount);
|
||||
public ItemStack removeItem(int slot, int amount) {
|
||||
return ContainerHelper.removeItem(this.inventory, slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot) {
|
||||
return Inventories.removeStack(this.inventory, slot);
|
||||
public ItemStack removeItemNoUpdate(int slot) {
|
||||
return ContainerHelper.takeItem(this.inventory, slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int slot, ItemStack stack) {
|
||||
public void setItem(int slot, ItemStack stack) {
|
||||
ItemStack itemStack = this.inventory.get(slot);
|
||||
boolean stackValid = !stack.isEmpty() && stack.isItemEqualIgnoreDamage(itemStack)
|
||||
&& ItemStack.areTagsEqual(stack, itemStack);
|
||||
boolean stackValid = !stack.isEmpty() && stack.sameItem(itemStack) && ItemStack.tagMatches(stack, itemStack);
|
||||
this.inventory.set(slot, stack);
|
||||
if (stack.getCount() > getMaxCountPerStack()) {
|
||||
stack.setCount(getMaxCountPerStack());
|
||||
if (stack.getCount() > getMaxStackSize()) {
|
||||
stack.setCount(getMaxStackSize());
|
||||
}
|
||||
if ((slot == 0 || slot == 1) && !stackValid) {
|
||||
this.smeltTimeTotal = this.getSmeltTime();
|
||||
this.smeltTime = 0;
|
||||
this.markDirty();
|
||||
this.setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected int getSmeltTime() {
|
||||
assert this.world != null;
|
||||
int smeltTime = this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, this, world)
|
||||
assert this.level != null;
|
||||
int smeltTime = this.level.getRecipeManager().getRecipeFor(AlloyingRecipe.TYPE, this, level)
|
||||
.map(AlloyingRecipe::getSmeltTime).orElse(0);
|
||||
if (smeltTime == 0) {
|
||||
smeltTime = this.world.getRecipeManager().getFirstMatch(RecipeType.BLASTING, this, world)
|
||||
.map(BlastingRecipe::getCookTime).orElse(200);
|
||||
smeltTime = this.level.getRecipeManager().getRecipeFor(RecipeType.BLASTING, this, level)
|
||||
.map(BlastingRecipe::getCookingTime).orElse(200);
|
||||
smeltTime /= 1.5;
|
||||
}
|
||||
return smeltTime;
|
||||
}
|
||||
|
||||
|
||||
public void dropExperience(Player player) {
|
||||
assert world != null;
|
||||
assert level != null;
|
||||
List<Recipe<?>> list = Lists.newArrayList();
|
||||
for (Entry<ResourceLocation> entry : this.recipesUsed.object2IntEntrySet()) {
|
||||
world.getRecipeManager().get(entry.getKey()).ifPresent((recipe) -> {
|
||||
level.getRecipeManager().byKey(entry.getKey()).ifPresent((recipe) -> {
|
||||
list.add(recipe);
|
||||
if (recipe instanceof AlloyingRecipe) {
|
||||
AlloyingRecipe alloying = (AlloyingRecipe) recipe;
|
||||
this.dropExperience(player.world, player.getPos(), entry.getIntValue(), alloying.getExperience());
|
||||
this.dropExperience(player.level, player.position(), entry.getIntValue(), alloying.getExperience());
|
||||
} else {
|
||||
BlastingRecipe blasting = (BlastingRecipe) recipe;
|
||||
this.dropExperience(player.world, player.getPos(), entry.getIntValue(), blasting.getExperience());
|
||||
this.dropExperience(player.level, player.position(), entry.getIntValue(), blasting.getExperience());
|
||||
}
|
||||
});
|
||||
}
|
||||
player.unlockRecipes(list);
|
||||
player.awardRecipes(list);
|
||||
this.recipesUsed.clear();
|
||||
}
|
||||
|
||||
private void dropExperience(Level world, Vec3d vec3d, int i, float f) {
|
||||
|
||||
private void dropExperience(Level world, Vec3 vec3d, int i, float f) {
|
||||
int j = Mth.floor(i * f);
|
||||
float g = Mth.fractionalPart(i * f);
|
||||
float g = Mth.frac(i * f);
|
||||
if (g != 0.0F && Math.random() < g) {
|
||||
j++;
|
||||
}
|
||||
|
||||
while (j > 0) {
|
||||
int k = ExperienceOrbEntity.roundToOrbSize(j);
|
||||
while(j > 0) {
|
||||
int k = ExperienceOrb.getExperienceValue(j);
|
||||
j -= k;
|
||||
world.spawnEntity(new ExperienceOrbEntity(world, vec3d.x, vec3d.y, vec3d.z, k));
|
||||
world.addFreshEntity(new ExperienceOrb(world, vec3d.x, vec3d.y, vec3d.z, k));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(Player player) {
|
||||
assert this.world != null;
|
||||
if (this.world.getBlockEntity(this.pos) != this) {
|
||||
public boolean stillValid(Player player) {
|
||||
assert this.level != null;
|
||||
if (this.level.getBlockEntity(this.worldPosition) != this) {
|
||||
return false;
|
||||
}
|
||||
return player.squaredDistanceTo(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D,
|
||||
this.pos.getZ() + 0.5D) <= 64.0D;
|
||||
return player.distanceToSqr(this.worldPosition.getX() + 0.5D, this.worldPosition.getY() + 0.5D, this.worldPosition.getZ() + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
public void clearContent() {
|
||||
this.inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Text getContainerName() {
|
||||
return new TranslatableText(String.format("block.%s.%s", BetterEnd.MOD_ID, EndStoneSmelter.ID));
|
||||
protected Component getDefaultName() {
|
||||
return new TranslatableComponent(String.format("block.%s.%s", BetterEnd.MOD_ID, EndStoneSmelter.ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ScreenHandler createScreenHandler(int syncId, PlayerInventory playerInventory) {
|
||||
protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
|
||||
return new EndStoneSmelterScreenHandler(syncId, playerInventory, this, propertyDelegate);
|
||||
}
|
||||
|
||||
|
@ -237,18 +234,17 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
}
|
||||
|
||||
boolean burning = this.isBurning();
|
||||
assert this.world != null;
|
||||
if (!this.world.isClientSide) {
|
||||
assert this.level != null;
|
||||
if (!this.level.isClientSide) {
|
||||
ItemStack fuel = this.inventory.get(2);
|
||||
if (!burning && (fuel.isEmpty() || inventory.get(0).isEmpty() && inventory.get(1).isEmpty())) {
|
||||
if (smeltTime > 0) {
|
||||
this.smeltTime = Mth.clamp(smeltTime - 2, 0, smeltTimeTotal);
|
||||
}
|
||||
} else {
|
||||
Recipe<?> recipe = this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, this, world)
|
||||
.orElse(null);
|
||||
Recipe<?> recipe = this.level.getRecipeManager().getRecipeFor(AlloyingRecipe.TYPE, this, level).orElse(null);
|
||||
if (recipe == null) {
|
||||
recipe = this.world.getRecipeManager().getFirstMatch(RecipeType.BLASTING, this, world).orElse(null);
|
||||
recipe = this.level.getRecipeManager().getRecipeFor(RecipeType.BLASTING, this, level).orElse(null);
|
||||
}
|
||||
boolean accepted = this.canAcceptRecipeOutput(recipe);
|
||||
if (!burning && accepted) {
|
||||
|
@ -258,13 +254,13 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
if (burning) {
|
||||
if (!fuel.isEmpty()) {
|
||||
Item item = fuel.getItem();
|
||||
fuel.decrement(1);
|
||||
fuel.shrink(1);
|
||||
if (fuel.isEmpty()) {
|
||||
Item remainFuel = item.getRecipeRemainder();
|
||||
Item remainFuel = item.getCraftingRemainingItem();
|
||||
this.inventory.set(2, remainFuel == null ? ItemStack.EMPTY : new ItemStack(remainFuel));
|
||||
}
|
||||
}
|
||||
this.markDirty();
|
||||
this.setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,7 +270,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
this.smeltTime = 0;
|
||||
this.smeltTimeTotal = this.getSmeltTime();
|
||||
this.craftRecipe(recipe);
|
||||
this.markDirty();
|
||||
this.setChanged();
|
||||
}
|
||||
} else {
|
||||
this.smeltTime = 0;
|
||||
|
@ -282,23 +278,24 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
}
|
||||
|
||||
if (initialBurning != burning) {
|
||||
this.world.setBlockAndUpdate(pos, world.getBlockState(pos).with(EndStoneSmelter.LIT, burning), 3);
|
||||
this.markDirty();
|
||||
this.level.setBlock(worldPosition, level.getBlockState(worldPosition).setValue(EndStoneSmelter.LIT, burning), 3);
|
||||
this.setChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean canAcceptRecipeOutput(Recipe<?> recipe) {
|
||||
if (recipe == null)
|
||||
return false;
|
||||
if (recipe == null) return false;
|
||||
boolean validInput;
|
||||
if (recipe instanceof AlloyingRecipe) {
|
||||
validInput = !inventory.get(0).isEmpty() && !inventory.get(1).isEmpty();
|
||||
validInput = !inventory.get(0).isEmpty() &&
|
||||
!inventory.get(1).isEmpty();
|
||||
} else {
|
||||
validInput = !inventory.get(0).isEmpty() || !inventory.get(1).isEmpty();
|
||||
validInput = !inventory.get(0).isEmpty() ||
|
||||
!inventory.get(1).isEmpty();
|
||||
}
|
||||
if (validInput) {
|
||||
ItemStack result = recipe.getOutput();
|
||||
ItemStack result = recipe.getResultItem();
|
||||
if (result.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -308,55 +305,54 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
if (output.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (!output.isItemEqualIgnoreDamage(result)) {
|
||||
if (!output.sameItem(result)) {
|
||||
return false;
|
||||
}
|
||||
if (outCount < this.getMaxCountPerStack() && outCount < output.getMaxCount()) {
|
||||
return this.getMaxCountPerStack() >= total;
|
||||
if (outCount < this.getMaxStackSize() && outCount < output.getMaxStackSize()) {
|
||||
return this.getMaxStackSize() >= total;
|
||||
}
|
||||
return output.getCount() < result.getMaxCount();
|
||||
return output.getCount() < result.getMaxStackSize();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void craftRecipe(Recipe<?> recipe) {
|
||||
if (recipe == null || !canAcceptRecipeOutput(recipe))
|
||||
return;
|
||||
|
||||
ItemStack result = recipe.getOutput();
|
||||
if (recipe == null || !canAcceptRecipeOutput(recipe)) return;
|
||||
|
||||
ItemStack result = recipe.getResultItem();
|
||||
ItemStack output = this.inventory.get(3);
|
||||
if (output.isEmpty()) {
|
||||
this.inventory.set(3, result.copy());
|
||||
} else if (output.getItem() == result.getItem()) {
|
||||
output.increment(result.getCount());
|
||||
output.grow(result.getCount());
|
||||
}
|
||||
|
||||
assert this.world != null;
|
||||
if (!this.world.isClientSide) {
|
||||
this.setLastRecipe(recipe);
|
||||
assert this.level != null;
|
||||
if (!this.level.isClientSide) {
|
||||
this.setRecipeUsed(recipe);
|
||||
}
|
||||
|
||||
|
||||
if (recipe instanceof AlloyingRecipe) {
|
||||
this.inventory.get(0).decrement(1);
|
||||
this.inventory.get(1).decrement(1);
|
||||
this.inventory.get(0).shrink(1);
|
||||
this.inventory.get(1).shrink(1);
|
||||
} else {
|
||||
if (!this.inventory.get(0).isEmpty()) {
|
||||
this.inventory.get(0).decrement(1);
|
||||
this.inventory.get(0).shrink(1);
|
||||
} else {
|
||||
this.inventory.get(1).decrement(1);
|
||||
this.inventory.get(1).shrink(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideRecipeInputs(RecipeFinder finder) {
|
||||
public void fillStackedContents(StackedContents finder) {
|
||||
for (ItemStack itemStack : this.inventory) {
|
||||
finder.addItem(itemStack);
|
||||
finder.accountStack(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastRecipe(Recipe<?> recipe) {
|
||||
public void setRecipeUsed(Recipe<?> recipe) {
|
||||
if (recipe != null) {
|
||||
ResourceLocation recipeId = recipe.getId();
|
||||
this.recipesUsed.addTo(recipeId, 1);
|
||||
|
@ -365,12 +361,12 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
}
|
||||
|
||||
@Override
|
||||
public Recipe<?> getLastRecipe() {
|
||||
public Recipe<?> getRecipeUsed() {
|
||||
return this.lastRecipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAvailableSlots(Direction side) {
|
||||
public int[] getSlotsForFace(Direction side) {
|
||||
if (side == Direction.DOWN) {
|
||||
return BOTTOM_SLOTS;
|
||||
}
|
||||
|
@ -378,12 +374,12 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(int slot, ItemStack stack, Direction dir) {
|
||||
return this.isValid(slot, stack);
|
||||
public boolean canPlaceItemThroughFace(int slot, ItemStack stack, Direction dir) {
|
||||
return this.canPlaceItem(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtract(int slot, ItemStack stack, Direction dir) {
|
||||
public boolean canTakeItemThroughFace(int slot, ItemStack stack, Direction dir) {
|
||||
if (dir == Direction.DOWN && slot == 2) {
|
||||
return stack.getItem() == Items.BUCKET;
|
||||
}
|
||||
|
@ -397,38 +393,38 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
Item item = fuel.getItem();
|
||||
return AVAILABLE_FUELS.getOrDefault(item, getFabricFuel(fuel));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
this.inventory = DefaultedList.ofSize(size(), ItemStack.EMPTY);
|
||||
Inventories.fromTag(tag, inventory);
|
||||
public void load(BlockState state, CompoundTag tag) {
|
||||
super.load(state, tag);
|
||||
this.inventory = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY);
|
||||
ContainerHelper.loadAllItems(tag, inventory);
|
||||
this.burnTime = tag.getShort("BurnTime");
|
||||
this.fuelTime = tag.getShort("FuelTime");
|
||||
this.smeltTime = tag.getShort("SmeltTime");
|
||||
this.smeltTimeTotal = tag.getShort("SmeltTimeTotal");
|
||||
CompoundTag compoundTag = tag.getCompound("RecipesUsed");
|
||||
for (String id : compoundTag.getKeys()) {
|
||||
for (String id : compoundTag.getAllKeys()) {
|
||||
this.recipesUsed.put(new ResourceLocation(id), compoundTag.getInt(id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
public CompoundTag save(CompoundTag tag) {
|
||||
super.save(tag);
|
||||
tag.putShort("BurnTime", (short) burnTime);
|
||||
tag.putShort("FuelTime", (short) fuelTime);
|
||||
tag.putShort("SmeltTime", (short) smeltTime);
|
||||
tag.putShort("SmeltTimeTotal", (short) smeltTimeTotal);
|
||||
Inventories.toTag(tag, inventory);
|
||||
ContainerHelper.saveAllItems(tag, inventory);
|
||||
CompoundTag usedRecipes = new CompoundTag();
|
||||
this.recipesUsed.forEach((identifier, integer) -> usedRecipes.putInt(identifier.toString(), integer));
|
||||
tag.put("RecipesUsed", usedRecipes);
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public boolean isValid(int slot, ItemStack stack) {
|
||||
|
||||
public boolean canPlaceItem(int slot, ItemStack stack) {
|
||||
if (slot == 3) {
|
||||
return false;
|
||||
} else if (slot != 2) {
|
||||
|
@ -449,14 +445,14 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity
|
|||
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;
|
||||
}
|
||||
|
||||
static {
|
||||
AbstractFurnaceBlockEntity.createFuelTimeMap().forEach((item, time) -> {
|
||||
AbstractFurnaceBlockEntity.getFuel().forEach((item, time) -> {
|
||||
if (time >= 2000) {
|
||||
registerFuel(item, time);
|
||||
}
|
||||
|
|
|
@ -1,51 +1,51 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
import ru.betterend.rituals.EternalRitual;
|
||||
|
||||
public class EternalPedestalEntity extends PedestalBlockEntity {
|
||||
private EternalRitual linkedRitual;
|
||||
|
||||
|
||||
public EternalPedestalEntity() {
|
||||
super(EndBlockEntities.ETERNAL_PEDESTAL);
|
||||
}
|
||||
|
||||
|
||||
public boolean hasRitual() {
|
||||
return linkedRitual != null;
|
||||
}
|
||||
|
||||
|
||||
public void linkRitual(EternalRitual ritual) {
|
||||
this.linkedRitual = ritual;
|
||||
}
|
||||
|
||||
|
||||
public EternalRitual getRitual() {
|
||||
return linkedRitual;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setLocation(Level world, BlockPos pos) {
|
||||
super.setLocation(world, pos);
|
||||
public void setLevelAndPosition(Level world, BlockPos pos) {
|
||||
super.setLevelAndPosition(world, pos);
|
||||
if (hasRitual()) {
|
||||
linkedRitual.setWorld(world);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
public CompoundTag save(CompoundTag tag) {
|
||||
if (hasRitual()) {
|
||||
tag.put("ritual", linkedRitual.toTag(new CompoundTag()));
|
||||
}
|
||||
return super.toTag(tag);
|
||||
return super.save(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fromTag(CompoundTag tag) {
|
||||
super.fromTag(tag);
|
||||
if (tag.contains("ritual")) {
|
||||
linkedRitual = new EternalRitual(world);
|
||||
linkedRitual = new EternalRitual(level);
|
||||
linkedRitual.fromTag(tag.getCompound("ritual"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
import ru.betterend.rituals.InfusionRitual;
|
||||
|
@ -9,31 +9,31 @@ import ru.betterend.rituals.InfusionRitual;
|
|||
public class InfusionPedestalEntity extends PedestalBlockEntity {
|
||||
|
||||
private InfusionRitual linkedRitual;
|
||||
|
||||
|
||||
public InfusionPedestalEntity() {
|
||||
super(EndBlockEntities.INFUSION_PEDESTAL);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setLocation(Level world, BlockPos pos) {
|
||||
super.setLocation(world, pos);
|
||||
public void setLevelAndPosition(Level world, BlockPos pos) {
|
||||
super.setLevelAndPosition(world, pos);
|
||||
if (hasRitual()) {
|
||||
linkedRitual.setLocation(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void linkRitual(InfusionRitual ritual) {
|
||||
linkedRitual = ritual;
|
||||
}
|
||||
|
||||
|
||||
public InfusionRitual getRitual() {
|
||||
return linkedRitual;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasRitual() {
|
||||
return linkedRitual != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (hasRitual()) {
|
||||
|
@ -43,18 +43,18 @@ public class InfusionPedestalEntity extends PedestalBlockEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
public CompoundTag save(CompoundTag tag) {
|
||||
if (hasRitual()) {
|
||||
tag.put("ritual", linkedRitual.toTag(new CompoundTag()));
|
||||
}
|
||||
return super.toTag(tag);
|
||||
return super.save(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fromTag(CompoundTag tag) {
|
||||
super.fromTag(tag);
|
||||
if (tag.contains("ritual")) {
|
||||
linkedRitual = new InfusionRitual(world, pos);
|
||||
linkedRitual = new InfusionRitual(level, worldPosition);
|
||||
linkedRitual.fromTag(tag.getCompound("ritual"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.world.level.block.entity.TickableBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.betterend.blocks.basis.PedestalBlock;
|
||||
import ru.betterend.registry.EndBlockEntities;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class PedestalBlockEntity extends BlockEntity implements Inventory, Tickable, BlockEntityClientSerializable {
|
||||
public class PedestalBlockEntity extends BlockEntity implements Container, TickableBlockEntity, BlockEntityClientSerializable {
|
||||
private ItemStack activeItem = ItemStack.EMPTY;
|
||||
|
||||
|
||||
private final int maxAge = 314;
|
||||
private int age;
|
||||
|
||||
|
||||
public PedestalBlockEntity() {
|
||||
super(EndBlockEntities.PEDESTAL);
|
||||
}
|
||||
|
||||
|
||||
public PedestalBlockEntity(BlockEntityType<?> type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
|
||||
public int getMaxAge() {
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
public int getContainerSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -46,71 +46,72 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack(int slot) {
|
||||
public ItemStack getItem(int slot) {
|
||||
return activeItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot, int amount) {
|
||||
return removeStack(slot);
|
||||
public ItemStack removeItem(int slot, int amount) {
|
||||
return removeItemNoUpdate(slot);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isValid(int slot, ItemStack stack) {
|
||||
public boolean canPlaceItem(int slot, ItemStack stack) {
|
||||
return isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
public void clearContent() {
|
||||
activeItem = ItemStack.EMPTY;
|
||||
markDirty();
|
||||
setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStack(int slot) {
|
||||
public ItemStack removeItemNoUpdate(int slot) {
|
||||
ItemStack stored = activeItem;
|
||||
clear();
|
||||
clearContent();
|
||||
return stored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStack(int slot, ItemStack stack) {
|
||||
public void setItem(int slot, ItemStack stack) {
|
||||
activeItem = stack;
|
||||
markDirty();
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
if (world != null && !world.isClientSide) {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
public void setChanged() {
|
||||
if (level != null && !level.isClientSide) {
|
||||
BlockState state = level.getBlockState(worldPosition);
|
||||
if (state.getBlock() instanceof PedestalBlock) {
|
||||
BlockState trueState = state.with(PedestalBlock.HAS_ITEM, !isEmpty());
|
||||
BlockState trueState = state.setValue(PedestalBlock.HAS_ITEM, !isEmpty());
|
||||
if (activeItem.getItem() == EndItems.ETERNAL_CRYSTAL) {
|
||||
trueState = trueState.with(PedestalBlock.HAS_LIGHT, true);
|
||||
trueState = trueState.setValue(PedestalBlock.HAS_LIGHT, true);
|
||||
} else {
|
||||
trueState = trueState.with(PedestalBlock.HAS_LIGHT, false);
|
||||
trueState = trueState.setValue(PedestalBlock.HAS_LIGHT, false);
|
||||
}
|
||||
world.setBlockAndUpdate(pos, trueState);
|
||||
level.setBlockAndUpdate(worldPosition, trueState);
|
||||
}
|
||||
}
|
||||
super.markDirty();
|
||||
super.setChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(Player player) {
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
public void load(BlockState state, CompoundTag tag) {
|
||||
super.load(state, tag);
|
||||
fromTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
tag.put("active_item", activeItem.toTag(new CompoundTag()));
|
||||
return super.toTag(tag);
|
||||
public CompoundTag save(CompoundTag tag) {
|
||||
tag.put("active_item", activeItem.save(new CompoundTag()));
|
||||
return super.save(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,13 +121,13 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
|||
|
||||
@Override
|
||||
public CompoundTag toClientTag(CompoundTag tag) {
|
||||
return toTag(tag);
|
||||
return save(tag);
|
||||
}
|
||||
|
||||
protected void fromTag(CompoundTag tag) {
|
||||
if (tag.contains("active_item")) {
|
||||
CompoundTag itemTag = tag.getCompound("active_item");
|
||||
activeItem = ItemStack.fromTag(itemTag);
|
||||
activeItem = ItemStack.of(itemTag);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,43 +1,41 @@
|
|||
package ru.betterend.blocks.entities.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||
import net.minecraft.world.level.block.AbstractChestBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.ChestBlock;
|
||||
import net.minecraft.world.level.block.DoubleBlockProperties;
|
||||
import net.minecraft.world.level.block.DoubleBlockProperties.PropertySource;
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.world.level.block.enums.ChestType;
|
||||
import net.minecraft.client.block.ChestAnimationProgress;
|
||||
import net.minecraft.client.model.ModelPart;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.LightmapCoordinatesRetriever;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.client.model.geom.ModelPart;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.AbstractChestBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.ChestBlock;
|
||||
import net.minecraft.world.level.block.DoubleBlockCombiner;
|
||||
import net.minecraft.world.level.block.DoubleBlockCombiner.NeighborCombineResult;
|
||||
import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.LidBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.ChestType;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Vector3f;
|
||||
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.basis.EndChestBlock;
|
||||
import ru.betterend.blocks.entities.EChestBlockEntity;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class EndChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlockEntity> {
|
||||
private static final HashMap<Block, RenderLayer[]> LAYERS = Maps.newHashMap();
|
||||
private static RenderLayer[] defaultLayer;
|
||||
private static final HashMap<Block, RenderType[]> LAYERS = Maps.newHashMap();
|
||||
private static RenderType[] defaultLayer;
|
||||
|
||||
private static final int ID_NORMAL = 0;
|
||||
private static final int ID_LEFT = 1;
|
||||
|
@ -57,97 +55,88 @@ public class EndChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlock
|
|||
super(blockEntityRenderDispatcher);
|
||||
|
||||
this.partC = new ModelPart(64, 64, 0, 19);
|
||||
this.partC.addCuboid(1.0F, 0.0F, 1.0F, 14.0F, 9.0F, 14.0F, 0.0F);
|
||||
this.partC.addBox(1.0F, 0.0F, 1.0F, 14.0F, 9.0F, 14.0F, 0.0F);
|
||||
this.partA = new ModelPart(64, 64, 0, 0);
|
||||
this.partA.addCuboid(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partA.pivotY = 9.0F;
|
||||
this.partA.pivotZ = 1.0F;
|
||||
this.partA.addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partA.y = 9.0F;
|
||||
this.partA.z = 1.0F;
|
||||
this.partB = new ModelPart(64, 64, 0, 0);
|
||||
this.partB.addCuboid(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partB.pivotY = 8.0F;
|
||||
this.partB.addBox(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partB.y = 8.0F;
|
||||
this.partRightC = new ModelPart(64, 64, 0, 19);
|
||||
this.partRightC.addCuboid(1.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F);
|
||||
this.partRightC.addBox(1.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F);
|
||||
this.partRightA = new ModelPart(64, 64, 0, 0);
|
||||
this.partRightA.addCuboid(1.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partRightA.pivotY = 9.0F;
|
||||
this.partRightA.pivotZ = 1.0F;
|
||||
this.partRightA.addBox(1.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partRightA.y = 9.0F;
|
||||
this.partRightA.z = 1.0F;
|
||||
this.partRightB = new ModelPart(64, 64, 0, 0);
|
||||
this.partRightB.addCuboid(15.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partRightB.pivotY = 8.0F;
|
||||
this.partRightB.addBox(15.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partRightB.y = 8.0F;
|
||||
this.partLeftC = new ModelPart(64, 64, 0, 19);
|
||||
this.partLeftC.addCuboid(0.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F);
|
||||
this.partLeftC.addBox(0.0F, 0.0F, 1.0F, 15.0F, 9.0F, 14.0F, 0.0F);
|
||||
this.partLeftA = new ModelPart(64, 64, 0, 0);
|
||||
this.partLeftA.addCuboid(0.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partLeftA.pivotY = 9.0F;
|
||||
this.partLeftA.pivotZ = 1.0F;
|
||||
this.partLeftA.addBox(0.0F, 0.0F, 0.0F, 15.0F, 5.0F, 14.0F, 0.0F);
|
||||
this.partLeftA.y = 9.0F;
|
||||
this.partLeftA.z = 1.0F;
|
||||
this.partLeftB = new ModelPart(64, 64, 0, 0);
|
||||
this.partLeftB.addCuboid(0.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partLeftB.pivotY = 8.0F;
|
||||
this.partLeftB.addBox(0.0F, -1.0F, 15.0F, 1.0F, 4.0F, 1.0F, 0.0F);
|
||||
this.partLeftB.y = 8.0F;
|
||||
}
|
||||
|
||||
public void render(EChestBlockEntity entity, float tickDelta, MatrixStack matrices,
|
||||
VertexConsumerProvider vertexConsumers, int light, int overlay) {
|
||||
public void render(EChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
|
||||
Level world = entity.getLevel();
|
||||
boolean worldExists = world != null;
|
||||
BlockState blockState = worldExists ? entity.getCachedState()
|
||||
: (BlockState) Blocks.CHEST.defaultBlockState().with(ChestBlock.FACING, Direction.SOUTH);
|
||||
ChestType chestType = blockState.contains(ChestBlock.CHEST_TYPE)
|
||||
? (ChestType) blockState.get(ChestBlock.CHEST_TYPE)
|
||||
: ChestType.SINGLE;
|
||||
BlockState blockState = worldExists ? entity.getBlockState() : (BlockState) Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.SOUTH);
|
||||
ChestType chestType = blockState.hasProperty(ChestBlock.TYPE) ? (ChestType) blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
|
||||
Block block = blockState.getBlock();
|
||||
if (block instanceof AbstractChestBlock) {
|
||||
AbstractChestBlock<?> abstractChestBlock = (AbstractChestBlock<?>) block;
|
||||
boolean isDouble = chestType != ChestType.SINGLE;
|
||||
float f = ((Direction) blockState.get(ChestBlock.FACING)).asRotation();
|
||||
PropertySource<? extends ChestBlockEntity> propertySource;
|
||||
float f = ((Direction) blockState.getValue(ChestBlock.FACING)).toYRot();
|
||||
NeighborCombineResult<? extends ChestBlockEntity> propertySource;
|
||||
|
||||
matrices.push();
|
||||
matrices.pushPose();
|
||||
matrices.translate(0.5D, 0.5D, 0.5D);
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-f));
|
||||
matrices.mulPose(Vector3f.YP.rotationDegrees(-f));
|
||||
matrices.translate(-0.5D, -0.5D, -0.5D);
|
||||
|
||||
if (worldExists) {
|
||||
propertySource = abstractChestBlock.getBlockEntitySource(blockState, world, entity.getPos(), true);
|
||||
propertySource = abstractChestBlock.combine(blockState, world, entity.getBlockPos(), true);
|
||||
} else {
|
||||
propertySource = DoubleBlockProperties.PropertyRetriever::getFallback;
|
||||
propertySource = DoubleBlockCombiner.Combiner::acceptNone;
|
||||
}
|
||||
|
||||
float pitch = ((Float2FloatFunction) propertySource
|
||||
.apply(ChestBlock.getAnimationProgressRetriever((ChestAnimationProgress) entity))).get(tickDelta);
|
||||
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner((LidBlockEntity) entity))).get(tickDelta);
|
||||
pitch = 1.0F - pitch;
|
||||
pitch = 1.0F - pitch * pitch * pitch;
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
int blockLight = ((Int2IntFunction) propertySource.apply(new LightmapCoordinatesRetriever()))
|
||||
.applyAsInt(light);
|
||||
int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light);
|
||||
|
||||
VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType);
|
||||
|
||||
if (isDouble) {
|
||||
if (chestType == ChestType.LEFT) {
|
||||
renderParts(matrices, vertexConsumer, this.partLeftA, this.partLeftB, this.partLeftC, pitch,
|
||||
blockLight, overlay);
|
||||
renderParts(matrices, vertexConsumer, this.partLeftA, this.partLeftB, this.partLeftC, pitch, blockLight, overlay);
|
||||
} else {
|
||||
renderParts(matrices, vertexConsumer, this.partRightA, this.partRightB, this.partRightC, pitch,
|
||||
blockLight, overlay);
|
||||
renderParts(matrices, vertexConsumer, this.partRightA, this.partRightB, this.partRightC, pitch, blockLight, overlay);
|
||||
}
|
||||
} else {
|
||||
renderParts(matrices, vertexConsumer, this.partA, this.partB, this.partC, pitch, blockLight, overlay);
|
||||
}
|
||||
|
||||
matrices.pop();
|
||||
matrices.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
private void renderParts(MatrixStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2,
|
||||
ModelPart modelPart3, float pitch, int light, int overlay) {
|
||||
modelPart.pitch = -(pitch * 1.5707964F);
|
||||
modelPart2.pitch = modelPart.pitch;
|
||||
private void renderParts(PoseStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2, ModelPart modelPart3, float pitch, int light, int overlay) {
|
||||
modelPart.xRot = -(pitch * 1.5707964F);
|
||||
modelPart2.xRot = modelPart.xRot;
|
||||
modelPart.render(matrices, vertices, light, overlay);
|
||||
modelPart2.render(matrices, vertices, light, overlay);
|
||||
modelPart3.render(matrices, vertices, light, overlay);
|
||||
}
|
||||
|
||||
private static RenderLayer getChestTexture(ChestType type, RenderLayer[] layers) {
|
||||
private static RenderType getChestTexture(ChestType type, RenderType[] layers) {
|
||||
switch (type) {
|
||||
case LEFT:
|
||||
return layers[ID_LEFT];
|
||||
|
@ -159,28 +148,28 @@ public class EndChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlock
|
|||
}
|
||||
}
|
||||
|
||||
public static VertexConsumer getConsumer(VertexConsumerProvider provider, Block block, ChestType chestType) {
|
||||
RenderLayer[] layers = LAYERS.getOrDefault(block, defaultLayer);
|
||||
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block, ChestType chestType) {
|
||||
RenderType[] layers = LAYERS.getOrDefault(block, defaultLayer);
|
||||
return provider.getBuffer(getChestTexture(chestType, layers));
|
||||
}
|
||||
|
||||
static {
|
||||
defaultLayer = new RenderLayer[] {
|
||||
RenderLayer.getEntityCutout(new ResourceLocation("textures/entity/chest/normal.png")),
|
||||
RenderLayer.getEntityCutout(new ResourceLocation("textures/entity/chest/normal_left.png")),
|
||||
RenderLayer.getEntityCutout(new ResourceLocation("textures/entity/chest/normal_right.png")) };
|
||||
|
||||
defaultLayer = new RenderType[] {
|
||||
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal.png")),
|
||||
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_left.png")),
|
||||
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png"))
|
||||
};
|
||||
|
||||
EndItems.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
Block block = ((BlockItem) item).getBlock();
|
||||
if (block instanceof EndChestBlock) {
|
||||
String name = Registry.BLOCK.getKey(block).getPath();
|
||||
LAYERS.put(block, new RenderLayer[] {
|
||||
RenderLayer.getEntityCutout(BetterEnd.makeID("textures/entity/chest/" + name + ".png")),
|
||||
RenderLayer
|
||||
.getEntityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_left.png")),
|
||||
RenderLayer.getEntityCutout(
|
||||
BetterEnd.makeID("textures/entity/chest/" + name + "_right.png")) });
|
||||
LAYERS.put(block, new RenderType[] {
|
||||
RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + ".png")),
|
||||
RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_left.png")),
|
||||
RenderType.entityCutout(BetterEnd.makeID("textures/entity/chest/" + name + "_right.png"))
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,122 +2,119 @@ package ru.betterend.blocks.entities.render;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.world.level.block.SignBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.SignBlock;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.TexturedRenderLayers;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.SignBlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.SignBlockEntityRenderer.SignModel;
|
||||
import net.minecraft.client.texture.NativeImage;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.text.OrderedText;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.SignType;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.SignRenderer.SignModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.SignBlock;
|
||||
import net.minecraft.world.level.block.StandingSignBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.WoodType;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Vector3f;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.basis.EndSignBlock;
|
||||
import ru.betterend.blocks.entities.ESignBlockEntity;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class EndSignBlockEntityRenderer extends BlockEntityRenderer<ESignBlockEntity> {
|
||||
private static final HashMap<Block, RenderLayer> LAYERS = Maps.newHashMap();
|
||||
private static RenderLayer defaultLayer;
|
||||
private final SignModel model = new SignBlockEntityRenderer.SignModel();
|
||||
private static final HashMap<Block, RenderType> LAYERS = Maps.newHashMap();
|
||||
private static RenderType defaultLayer;
|
||||
private final SignModel model = new SignRenderer.SignModel();
|
||||
|
||||
public EndSignBlockEntityRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
public void render(ESignBlockEntity signBlockEntity, float tickDelta, MatrixStack matrixStack,
|
||||
VertexConsumerProvider provider, int light, int overlay) {
|
||||
BlockState state = signBlockEntity.getCachedState();
|
||||
matrixStack.push();
|
||||
public void render(ESignBlockEntity signBlockEntity, float tickDelta, PoseStack matrixStack,
|
||||
MultiBufferSource provider, int light, int overlay) {
|
||||
BlockState state = signBlockEntity.getBlockState();
|
||||
matrixStack.pushPose();
|
||||
|
||||
matrixStack.translate(0.5D, 0.5D, 0.5D);
|
||||
float angle = -((float) ((Integer) state.getValue(SignBlock.ROTATION) * 360) / 16.0F);
|
||||
float angle = -((float) ((Integer) state.getValue(StandingSignBlock.ROTATION) * 360) / 16.0F);
|
||||
|
||||
BlockState blockState = signBlockEntity.getCachedState();
|
||||
if (blockState.get(EndSignBlock.FLOOR)) {
|
||||
matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(angle));
|
||||
this.model.foot.visible = true;
|
||||
BlockState blockState = signBlockEntity.getBlockState();
|
||||
if (blockState.getValue(EndSignBlock.FLOOR)) {
|
||||
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle));
|
||||
this.model.stick.visible = true;
|
||||
} else {
|
||||
matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(angle + 180));
|
||||
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180));
|
||||
matrixStack.translate(0.0D, -0.3125D, -0.4375D);
|
||||
this.model.foot.visible = false;
|
||||
this.model.stick.visible = false;
|
||||
}
|
||||
|
||||
matrixStack.push();
|
||||
matrixStack.pushPose();
|
||||
matrixStack.scale(0.6666667F, -0.6666667F, -0.6666667F);
|
||||
VertexConsumer vertexConsumer = getConsumer(provider, state.getBlock());
|
||||
model.field.render(matrixStack, vertexConsumer, light, overlay);
|
||||
model.foot.render(matrixStack, vertexConsumer, light, overlay);
|
||||
matrixStack.pop();
|
||||
TextRenderer textRenderer = dispatcher.getTextRenderer();
|
||||
model.sign.render(matrixStack, vertexConsumer, light, overlay);
|
||||
model.stick.render(matrixStack, vertexConsumer, light, overlay);
|
||||
matrixStack.popPose();
|
||||
Font textRenderer = renderer.getFont();
|
||||
matrixStack.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D);
|
||||
matrixStack.scale(0.010416667F, -0.010416667F, 0.010416667F);
|
||||
int m = signBlockEntity.getTextColor().getSignColor();
|
||||
int n = (int) (NativeImage.getRed(m) * 0.4D);
|
||||
int o = (int) (NativeImage.getGreen(m) * 0.4D);
|
||||
int p = (int) (NativeImage.getBlue(m) * 0.4D);
|
||||
int q = NativeImage.getAbgrColor(0, p, o, n);
|
||||
int m = signBlockEntity.getColor().getTextColor();
|
||||
int n = (int) (NativeImage.getR(m) * 0.4D);
|
||||
int o = (int) (NativeImage.getG(m) * 0.4D);
|
||||
int p = (int) (NativeImage.getB(m) * 0.4D);
|
||||
int q = NativeImage.combine(0, p, o, n);
|
||||
|
||||
for (int s = 0; s < 4; ++s) {
|
||||
OrderedText orderedText = signBlockEntity.getTextBeingEditedOnRow(s, (text) -> {
|
||||
List<OrderedText> list = textRenderer.wrapLines(text, 90);
|
||||
return list.isEmpty() ? OrderedText.EMPTY : (OrderedText) list.get(0);
|
||||
FormattedCharSequence orderedText = signBlockEntity.getRenderMessage(s, (text) -> {
|
||||
List<FormattedCharSequence> list = textRenderer.split(text, 90);
|
||||
return list.isEmpty() ? FormattedCharSequence.EMPTY : (FormattedCharSequence) list.get(0);
|
||||
});
|
||||
if (orderedText != null) {
|
||||
float t = (float) (-textRenderer.getWidth(orderedText) / 2);
|
||||
textRenderer.draw((OrderedText) orderedText, t, (float) (s * 10 - 20), q, false,
|
||||
matrixStack.peek().getModel(), provider, false, 0, light);
|
||||
float t = (float) (-textRenderer.width(orderedText) / 2);
|
||||
textRenderer.drawInBatch((FormattedCharSequence) orderedText, t, (float) (s * 10 - 20), q, false, matrixStack.last().pose(), provider, false, 0, light);
|
||||
}
|
||||
}
|
||||
|
||||
matrixStack.pop();
|
||||
matrixStack.popPose();
|
||||
}
|
||||
|
||||
public static SpriteIdentifier getModelTexture(Block block) {
|
||||
SignType signType2;
|
||||
public static Material getModelTexture(Block block) {
|
||||
WoodType signType2;
|
||||
if (block instanceof SignBlock) {
|
||||
signType2 = ((SignBlock) block).getSignType();
|
||||
signType2 = ((SignBlock) block).type();
|
||||
} else {
|
||||
signType2 = SignType.OAK;
|
||||
signType2 = WoodType.OAK;
|
||||
}
|
||||
|
||||
return TexturedRenderLayers.getSignTextureId(signType2);
|
||||
return Sheets.signTexture(signType2);
|
||||
}
|
||||
|
||||
public static VertexConsumer getConsumer(VertexConsumerProvider provider, Block block) {
|
||||
|
||||
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block) {
|
||||
return provider.getBuffer(LAYERS.getOrDefault(block, defaultLayer));
|
||||
}
|
||||
|
||||
static {
|
||||
defaultLayer = RenderLayer.getEntitySolid(new ResourceLocation("textures/entity/sign/oak.png"));
|
||||
|
||||
defaultLayer = RenderType.entitySolid(new ResourceLocation("textures/entity/sign/oak.png"));
|
||||
|
||||
EndItems.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
Block block = ((BlockItem) item).getBlock();
|
||||
if (block instanceof EndSignBlock) {
|
||||
String name = Registry.BLOCK.getKey(block).getPath();
|
||||
RenderLayer layer = RenderLayer
|
||||
.getEntitySolid(BetterEnd.makeID("textures/entity/sign/" + name + ".png"));
|
||||
RenderType layer = RenderType.entitySolid(BetterEnd.makeID("textures/entity/sign/" + name + ".png"));
|
||||
LAYERS.put(block, layer);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
package ru.betterend.blocks.entities.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.betterend.blocks.EternalPedestal;
|
||||
import ru.betterend.blocks.basis.PedestalBlock;
|
||||
import ru.betterend.blocks.entities.PedestalBlockEntity;
|
||||
|
@ -27,31 +27,29 @@ import ru.betterend.registry.EndItems;
|
|||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEntityRenderer<T> {
|
||||
|
||||
|
||||
public PedestalItemRenderer(BlockEntityRenderDispatcher dispatcher) {
|
||||
super(dispatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(T blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers,
|
||||
int light, int overlay) {
|
||||
public void render(T blockEntity, float tickDelta, PoseStack matrices,
|
||||
MultiBufferSource vertexConsumers, int light, int overlay) {
|
||||
|
||||
Level world = blockEntity.getLevel();
|
||||
if (world == null || blockEntity.isEmpty())
|
||||
return;
|
||||
if (world == null || blockEntity.isEmpty()) return;
|
||||
|
||||
BlockState state = world.getBlockState(blockEntity.getPos());
|
||||
if (!(state.getBlock() instanceof PedestalBlock))
|
||||
return;
|
||||
BlockState state = world.getBlockState(blockEntity.getBlockPos());
|
||||
if (!(state.getBlock() instanceof PedestalBlock)) return;
|
||||
|
||||
ItemStack activeItem = blockEntity.getItem(0);
|
||||
|
||||
ItemStack activeItem = blockEntity.getStack(0);
|
||||
|
||||
matrices.push();
|
||||
matrices.pushPose();
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
BakedModel model = minecraft.getItemRenderer().getHeldItemModel(activeItem, world, null);
|
||||
Vector3f translate = model.getTransformation().ground.translation;
|
||||
BakedModel model = minecraft.getItemRenderer().getModel(activeItem, world, null);
|
||||
Vector3f translate = model.getTransforms().ground.translation;
|
||||
PedestalBlock pedestal = (PedestalBlock) state.getBlock();
|
||||
matrices.translate(translate.getX(), translate.getY(), translate.getZ());
|
||||
matrices.translate(translate.x(), translate.y(), translate.z());
|
||||
matrices.translate(0.5, pedestal.getHeight(state), 0.5);
|
||||
if (activeItem.getItem() instanceof BlockItem) {
|
||||
matrices.scale(1.5F, 1.5F, 1.5F);
|
||||
|
@ -61,10 +59,9 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEn
|
|||
int age = blockEntity.getAge();
|
||||
if (state.is(EndBlocks.ETERNAL_PEDESTAL) && state.getValue(EternalPedestal.ACTIVATED)) {
|
||||
float[] colors = EternalCrystalRenderer.colors(age);
|
||||
int y = blockEntity.getPos().getY();
|
||||
|
||||
BeamRenderer.renderLightBeam(matrices, vertexConsumers, age, tickDelta, -y, 1024 - y, colors, 0.25F, 0.13F,
|
||||
0.16F);
|
||||
int y = blockEntity.getBlockPos().getY();
|
||||
|
||||
BeamRenderer.renderLightBeam(matrices, vertexConsumers, age, tickDelta, -y, 1024 - y, colors, 0.25F, 0.13F, 0.16F);
|
||||
float altitude = Mth.sin((blockEntity.getAge() + tickDelta) / 10.0F) * 0.1F + 0.1F;
|
||||
matrices.translate(0.0D, altitude, 0.0D);
|
||||
}
|
||||
|
@ -74,10 +71,9 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEn
|
|||
EternalCrystalRenderer.render(age, tickDelta, matrices, vertexConsumers, light);
|
||||
} else {
|
||||
float rotation = (age + tickDelta) / 25.0F + 6.0F;
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(rotation));
|
||||
minecraft.getItemRenderer().renderItem(activeItem, ModelTransformation.Mode.GROUND, false, matrices,
|
||||
vertexConsumers, light, overlay, model);
|
||||
matrices.mulPose(Vector3f.YP.rotation(rotation));
|
||||
minecraft.getItemRenderer().render(activeItem, ItemTransforms.TransformType.GROUND, false, matrices, vertexConsumers, light, overlay, model);
|
||||
}
|
||||
matrices.pop();
|
||||
matrices.popPose();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue