Continue mapping migration

This commit is contained in:
Aleksey 2021-04-12 21:38:22 +03:00
parent 99ade39404
commit f03fd03bd0
499 changed files with 12567 additions and 12723 deletions

View file

@ -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);
}
}