Start migration

This commit is contained in:
Aleksey 2021-04-08 21:55:07 +03:00
parent 6630ce0cab
commit 47ed597358
491 changed files with 12045 additions and 11953 deletions

View file

@ -1,8 +1,8 @@
package ru.betterend.blocks.entities;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.particle.ParticleTypes;
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 ru.betterend.blocks.HydrothermalVentBlock;
import ru.betterend.registry.EndBlockEntities;
@ -21,11 +21,10 @@ public class BlockEntityHydrothermalVent extends BlockEntity implements Tickable
double y = pos.getY() + 0.9 + world.random.nextDouble() * 0.3;
double z = pos.getZ() + world.random.nextDouble();
BlockState state = getCachedState();
if (state.isOf(EndBlocks.HYDROTHERMAL_VENT) && state.get(HydrothermalVentBlock.ACTIVATED)) {
if (state.get(HydrothermalVentBlock.WATERLOGGED)) {
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 {
} else {
world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0);
}
}

View file

@ -1,25 +1,25 @@
package ru.betterend.blocks.entities;
import net.minecraft.block.BarrelBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
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.PlayerEntity;
import net.minecraft.world.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventories;
import net.minecraft.item.ItemStack;
import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import ru.betterend.blocks.basis.EndBarrelBlock;
import ru.betterend.registry.EndBlockEntities;
@ -124,7 +124,7 @@ public class EBarrelBlockEntity extends LootableContainerBlockEntity {
}
private void setOpen(BlockState state, boolean open) {
this.world.setBlockState(this.getPos(), (BlockState) state.with(BarrelBlock.OPEN, open), 3);
this.world.setBlockAndUpdate(this.getPos(), (BlockState) state.with(BarrelBlock.OPEN, open), 3);
}
private void playSound(BlockState blockState, SoundEvent soundEvent) {
@ -132,7 +132,7 @@ public class EBarrelBlockEntity extends LootableContainerBlockEntity {
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.playSound((PlayerEntity) null, d, e, f, soundEvent, SoundCategory.BLOCKS, 0.5F,
this.world.playLocalSound((PlayerEntity) null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F,
this.world.random.nextFloat() * 0.1F + 0.9F);
}
}

View file

@ -1,6 +1,6 @@
package ru.betterend.blocks.entities;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import ru.betterend.registry.EndBlockEntities;
public class EChestBlockEntity extends ChestBlockEntity {

View file

@ -1,8 +1,8 @@
package ru.betterend.blocks.entities;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.recipe.RecipeType;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.world.entity.player.PlayerInventory;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.screen.FurnaceScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text;

View file

@ -1,7 +1,7 @@
package ru.betterend.blocks.entities;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import ru.betterend.registry.EndBlockEntities;
public class ESignBlockEntity extends SignBlockEntity {

View file

@ -10,50 +10,51 @@ 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.block.BlockState;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.LockableContainerBlockEntity;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
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.world.entity.player.PlayerEntity;
import net.minecraft.world.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.SidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemConvertible;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.BlastingRecipe;
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.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.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Tickable;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.level.Level;
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 LockableContainerBlockEntity
implements SidedInventory, RecipeUnlocker, RecipeInputProvider, Tickable {
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<Identifier> recipesUsed;
private final Object2IntOpenHashMap<ResourceLocation> recipesUsed;
protected DefaultedList<ItemStack> inventory;
protected final PropertyDelegate propertyDelegate;
private Recipe<?> lastRecipe;
@ -61,47 +62,47 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
private int smeltTime;
private int burnTime;
private int fuelTime;
public EndStoneSmelterBlockEntity() {
super(EndBlockEntities.END_STONE_SMELTER);
this.inventory = DefaultedList.ofSize(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 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;
}
}
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 size() {
return 4;
}
};
}
private boolean isBurning() {
@ -145,7 +146,8 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
@Override
public void setStack(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.isItemEqualIgnoreDamage(itemStack)
&& ItemStack.areTagsEqual(stack, itemStack);
this.inventory.set(slot, stack);
if (stack.getCount() > getMaxCountPerStack()) {
stack.setCount(getMaxCountPerStack());
@ -156,23 +158,23 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
this.markDirty();
}
}
protected int getSmeltTime() {
assert this.world != null;
int smeltTime = this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, this, world)
.map(AlloyingRecipe::getSmeltTime).orElse(0);
if (smeltTime == 0) {
smeltTime = this.world.getRecipeManager().getFirstMatch(RecipeType.BLASTING, this, world)
.map(BlastingRecipe::getCookTime).orElse(200);
.map(BlastingRecipe::getCookTime).orElse(200);
smeltTime /= 1.5;
}
return smeltTime;
}
public void dropExperience(PlayerEntity player) {
assert world != null;
List<Recipe<?>> list = Lists.newArrayList();
for (Entry<Identifier> entry : this.recipesUsed.object2IntEntrySet()) {
for (Entry<ResourceLocation> entry : this.recipesUsed.object2IntEntrySet()) {
world.getRecipeManager().get(entry.getKey()).ifPresent((recipe) -> {
list.add(recipe);
if (recipe instanceof AlloyingRecipe) {
@ -187,15 +189,15 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
player.unlockRecipes(list);
this.recipesUsed.clear();
}
private void dropExperience(World world, Vec3d vec3d, int i, float f) {
int j = MathHelper.floor(i * f);
float g = MathHelper.fractionalPart(i * f);
private void dropExperience(Level world, Vec3d vec3d, int i, float f) {
int j = Mth.floor(i * f);
float g = Mth.fractionalPart(i * f);
if (g != 0.0F && Math.random() < g) {
j++;
}
while(j > 0) {
while (j > 0) {
int k = ExperienceOrbEntity.roundToOrbSize(j);
j -= k;
world.spawnEntity(new ExperienceOrbEntity(world, vec3d.x, vec3d.y, vec3d.z, k));
@ -208,7 +210,8 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
if (this.world.getBlockEntity(this.pos) != 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.squaredDistanceTo(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D,
this.pos.getZ() + 0.5D) <= 64.0D;
}
@Override
@ -235,14 +238,15 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
boolean burning = this.isBurning();
assert this.world != null;
if (!this.world.isClient) {
if (!this.world.isClientSide) {
ItemStack fuel = this.inventory.get(2);
if (!burning && (fuel.isEmpty() || inventory.get(0).isEmpty() && inventory.get(1).isEmpty())) {
if (smeltTime > 0) {
this.smeltTime = MathHelper.clamp(smeltTime - 2, 0, smeltTimeTotal);
this.smeltTime = Mth.clamp(smeltTime - 2, 0, smeltTimeTotal);
}
} else {
Recipe<?> recipe = this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, this, world).orElse(null);
Recipe<?> recipe = this.world.getRecipeManager().getFirstMatch(AlloyingRecipe.TYPE, this, world)
.orElse(null);
if (recipe == null) {
recipe = this.world.getRecipeManager().getFirstMatch(RecipeType.BLASTING, this, world).orElse(null);
}
@ -278,21 +282,20 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
}
if (initialBurning != burning) {
this.world.setBlockState(pos, world.getBlockState(pos).with(EndStoneSmelter.LIT, burning), 3);
this.world.setBlockAndUpdate(pos, world.getBlockState(pos).with(EndStoneSmelter.LIT, burning), 3);
this.markDirty();
}
}
}
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();
@ -317,8 +320,9 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
}
private void craftRecipe(Recipe<?> recipe) {
if (recipe == null || !canAcceptRecipeOutput(recipe)) return;
if (recipe == null || !canAcceptRecipeOutput(recipe))
return;
ItemStack result = recipe.getOutput();
ItemStack output = this.inventory.get(3);
if (output.isEmpty()) {
@ -328,10 +332,10 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
}
assert this.world != null;
if (!this.world.isClient) {
if (!this.world.isClientSide) {
this.setLastRecipe(recipe);
}
if (recipe instanceof AlloyingRecipe) {
this.inventory.get(0).decrement(1);
this.inventory.get(1).decrement(1);
@ -354,7 +358,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
@Override
public void setLastRecipe(Recipe<?> recipe) {
if (recipe != null) {
Identifier recipeId = recipe.getId();
ResourceLocation recipeId = recipe.getId();
this.recipesUsed.addTo(recipeId, 1);
this.lastRecipe = recipe;
}
@ -393,7 +397,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
Item item = fuel.getItem();
return AVAILABLE_FUELS.getOrDefault(item, getFabricFuel(fuel));
}
@Override
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
@ -405,10 +409,10 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
this.smeltTimeTotal = tag.getShort("SmeltTimeTotal");
CompoundTag compoundTag = tag.getCompound("RecipesUsed");
for (String id : compoundTag.getKeys()) {
this.recipesUsed.put(new Identifier(id), compoundTag.getInt(id));
this.recipesUsed.put(new ResourceLocation(id), compoundTag.getInt(id));
}
}
@Override
public CompoundTag toTag(CompoundTag tag) {
super.toTag(tag);
@ -420,10 +424,10 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
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) {
if (slot == 3) {
return false;
@ -445,7 +449,7 @@ public class EndStoneSmelterBlockEntity extends LockableContainerBlockEntity imp
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;

View file

@ -1,32 +1,32 @@
package ru.betterend.blocks.entities;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.core.BlockPos;
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(World world, BlockPos pos) {
public void setLocation(Level world, BlockPos pos) {
super.setLocation(world, pos);
if (hasRitual()) {
linkedRitual.setWorld(world);

View file

@ -1,39 +1,39 @@
package ru.betterend.blocks.entities;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import ru.betterend.registry.EndBlockEntities;
import ru.betterend.rituals.InfusionRitual;
public class InfusionPedestalEntity extends PedestalBlockEntity {
private InfusionRitual linkedRitual;
public InfusionPedestalEntity() {
super(EndBlockEntities.INFUSION_PEDESTAL);
}
@Override
public void setLocation(World world, BlockPos pos) {
public void setLocation(Level world, BlockPos pos) {
super.setLocation(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()) {

View file

@ -1,12 +1,12 @@
package ru.betterend.blocks.entities;
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Tickable;
import ru.betterend.blocks.basis.PedestalBlock;
@ -15,22 +15,22 @@ import ru.betterend.registry.EndItems;
public class PedestalBlockEntity extends BlockEntity implements Inventory, Tickable, 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;
}
@ -54,7 +54,7 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
public ItemStack removeStack(int slot, int amount) {
return removeStack(slot);
}
@Override
public boolean isValid(int slot, ItemStack stack) {
return isEmpty();
@ -78,10 +78,10 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
activeItem = stack;
markDirty();
}
@Override
public void markDirty() {
if (world != null && !world.isClient) {
if (world != null && !world.isClientSide) {
BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof PedestalBlock) {
BlockState trueState = state.with(PedestalBlock.HAS_ITEM, !isEmpty());
@ -90,18 +90,17 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
} else {
trueState = trueState.with(PedestalBlock.HAS_LIGHT, false);
}
world.setBlockState(pos, trueState);
world.setBlockAndUpdate(pos, trueState);
}
}
super.markDirty();
}
@Override
public boolean canPlayerUse(PlayerEntity player) {
return true;
}
@Override
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);

View file

@ -6,15 +6,15 @@ import com.google.common.collect.Maps;
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
import net.minecraft.block.AbstractChestBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.DoubleBlockProperties;
import net.minecraft.block.DoubleBlockProperties.PropertySource;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.enums.ChestType;
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;
@ -25,11 +25,11 @@ import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.LightmapCoordinatesRetriever;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.item.BlockItem;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.item.BlockItem;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.world.level.Level;
import ru.betterend.BetterEnd;
import ru.betterend.blocks.basis.EndChestBlock;
import ru.betterend.blocks.entities.EChestBlockEntity;
@ -85,11 +85,15 @@ public class EndChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlock
this.partLeftB.pivotY = 8.0F;
}
public void render(EChestBlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
World world = entity.getWorld();
public void render(EChestBlockEntity entity, float tickDelta, MatrixStack matrices,
VertexConsumerProvider vertexConsumers, int light, int overlay) {
Level world = entity.getLevel();
boolean worldExists = world != null;
BlockState blockState = worldExists ? entity.getCachedState() : (BlockState) Blocks.CHEST.getDefaultState().with(ChestBlock.FACING, Direction.SOUTH);
ChestType chestType = blockState.contains(ChestBlock.CHEST_TYPE) ? (ChestType) blockState.get(ChestBlock.CHEST_TYPE) : ChestType.SINGLE;
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;
Block block = blockState.getBlock();
if (block instanceof AbstractChestBlock) {
AbstractChestBlock<?> abstractChestBlock = (AbstractChestBlock<?>) block;
@ -108,19 +112,23 @@ public class EndChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlock
propertySource = DoubleBlockProperties.PropertyRetriever::getFallback;
}
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.getAnimationProgressRetriever((ChestAnimationProgress) entity))).get(tickDelta);
float pitch = ((Float2FloatFunction) propertySource
.apply(ChestBlock.getAnimationProgressRetriever((ChestAnimationProgress) 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 LightmapCoordinatesRetriever()))
.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);
@ -130,7 +138,8 @@ public class EndChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlock
}
}
private void renderParts(MatrixStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2, ModelPart modelPart3, float pitch, int light, int overlay) {
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;
modelPart.render(matrices, vertices, light, overlay);
@ -157,21 +166,21 @@ public class EndChestBlockEntityRenderer extends BlockEntityRenderer<EChestBlock
static {
defaultLayer = new RenderLayer[] {
RenderLayer.getEntityCutout(new Identifier("textures/entity/chest/normal.png")),
RenderLayer.getEntityCutout(new Identifier("textures/entity/chest/normal_left.png")),
RenderLayer.getEntityCutout(new Identifier("textures/entity/chest/normal_right.png"))
};
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")) };
EndItems.getModBlocks().forEach((item) -> {
if (item instanceof BlockItem) {
Block block = ((BlockItem) item).getBlock();
if (block instanceof EndChestBlock) {
String name = Registry.BLOCK.getId(block).getPath();
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"))
});
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")) });
}
}
});

View file

@ -5,10 +5,10 @@ import java.util.List;
import com.google.common.collect.Maps;
import net.minecraft.block.AbstractSignBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.SignBlock;
import net.minecraft.world.level.block.AbstractSignBlock;
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;
@ -22,11 +22,11 @@ import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.item.BlockItem;
import net.minecraft.world.item.BlockItem;
import net.minecraft.text.OrderedText;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.SignType;
import net.minecraft.util.registry.Registry;
import net.minecraft.core.Registry;
import ru.betterend.BetterEnd;
import ru.betterend.blocks.basis.EndSignBlock;
import ru.betterend.blocks.entities.ESignBlockEntity;
@ -47,7 +47,7 @@ public class EndSignBlockEntityRenderer extends BlockEntityRenderer<ESignBlockEn
matrixStack.push();
matrixStack.translate(0.5D, 0.5D, 0.5D);
float angle = -((float) ((Integer) state.get(SignBlock.ROTATION) * 360) / 16.0F);
float angle = -((float) ((Integer) state.getValue(SignBlock.ROTATION) * 360) / 16.0F);
BlockState blockState = signBlockEntity.getCachedState();
if (blockState.get(EndSignBlock.FLOOR)) {
@ -81,7 +81,8 @@ public class EndSignBlockEntityRenderer extends BlockEntityRenderer<ESignBlockEn
});
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);
textRenderer.draw((OrderedText) orderedText, t, (float) (s * 10 - 20), q, false,
matrixStack.peek().getModel(), provider, false, 0, light);
}
}
@ -98,25 +99,25 @@ public class EndSignBlockEntityRenderer extends BlockEntityRenderer<ESignBlockEn
return TexturedRenderLayers.getSignTextureId(signType2);
}
public static VertexConsumer getConsumer(VertexConsumerProvider provider, Block block) {
return provider.getBuffer(LAYERS.getOrDefault(block, defaultLayer));
}
static {
defaultLayer = RenderLayer.getEntitySolid(new Identifier("textures/entity/sign/oak.png"));
defaultLayer = RenderLayer.getEntitySolid(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.getId(block).getPath();
RenderLayer layer = RenderLayer.getEntitySolid(BetterEnd.makeID("textures/entity/sign/" + name + ".png"));
String name = Registry.BLOCK.getKey(block).getPath();
RenderLayer layer = RenderLayer
.getEntitySolid(BetterEnd.makeID("textures/entity/sign/" + name + ".png"));
LAYERS.put(block, layer);
}
}
});
}
}

View file

@ -2,7 +2,7 @@ package ru.betterend.blocks.entities.render;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
@ -11,11 +11,11 @@ import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
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 ru.betterend.blocks.EternalPedestal;
import ru.betterend.blocks.basis.PedestalBlock;
import ru.betterend.blocks.entities.PedestalBlockEntity;
@ -27,21 +27,23 @@ 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, MatrixStack matrices, VertexConsumerProvider vertexConsumers,
int light, int overlay) {
World world = blockEntity.getWorld();
if (world == null || blockEntity.isEmpty()) return;
Level world = blockEntity.getLevel();
if (world == null || blockEntity.isEmpty())
return;
BlockState state = world.getBlockState(blockEntity.getPos());
if (!(state.getBlock() instanceof PedestalBlock)) return;
if (!(state.getBlock() instanceof PedestalBlock))
return;
ItemStack activeItem = blockEntity.getStack(0);
matrices.push();
@ -57,12 +59,13 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEn
matrices.scale(1.25F, 1.25F, 1.25F);
}
int age = blockEntity.getAge();
if (state.isOf(EndBlocks.ETERNAL_PEDESTAL) && state.get(EternalPedestal.ACTIVATED)) {
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);
float altitude = MathHelper.sin((blockEntity.getAge() + tickDelta) / 10.0F) * 0.1F + 0.1F;
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);
}
if (activeItem.getItem() == Items.END_CRYSTAL) {
@ -72,7 +75,8 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEn
} 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);
minecraft.getItemRenderer().renderItem(activeItem, ModelTransformation.Mode.GROUND, false, matrices,
vertexConsumers, light, overlay, model);
}
matrices.pop();
}