Skip to content

Commit

Permalink
Ball Loots converted to cobblemon's models
Browse files Browse the repository at this point in the history
  • Loading branch information
Waterpicker committed Oct 23, 2023
1 parent b0b200d commit 889afbb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import generations.gg.generations.core.generationscore.client.render.rarecandy.BlockObjectInstance;
import generations.gg.generations.core.generationscore.client.render.rarecandy.ModelRegistry;
import generations.gg.generations.core.generationscore.world.level.block.BallLootBlock;
import generations.gg.generations.core.generationscore.world.level.block.entities.BallLootBlockEntity;
import generations.gg.generations.core.generationscore.world.level.block.generic.GenericModelBlock;
import gg.generations.rarecandy.renderer.rendering.ObjectInstance;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.item.ItemDisplayContext;
import org.joml.Matrix4f;

public class PokeLootRendrer implements BlockEntityRenderer<BallLootBlockEntity> {
Expand All @@ -18,31 +22,20 @@ public PokeLootRendrer(BlockEntityRendererProvider.Context ctx) {}

@Override
public void render(BallLootBlockEntity blockEntity, float partialTick, PoseStack stack, MultiBufferSource buffer, int packedLight, int packedOverlay) {
if (!(blockEntity.isVisible() && blockEntity.getBlockState().getBlock() instanceof GenericModelBlock<?> block && block.canRender(blockEntity.getLevel(), blockEntity.getBlockPos(), blockEntity.getBlockState()))) return;
stack.pushPose();
if (blockEntity.objectInstance == null) {
blockEntity.objectInstance = new ObjectInstance[] { new BlockObjectInstance(new Matrix4f(), new Matrix4f(), "default") };
}

var primeInstance = blockEntity.objectInstance[0];

if (!primeInstance.materialId().equals(blockEntity.getVariant())) {
primeInstance.setVariant(blockEntity.getVariant());
}

if (!(blockEntity.isVisible() && blockEntity.getBlockState().getBlock() instanceof BallLootBlock block && block.canRender(blockEntity.getLevel(), blockEntity.getBlockPos(), blockEntity.getBlockState()))) return;

((BlockObjectInstance) primeInstance).setLight(packedLight);
stack.pushPose();

var angle = -block.getAngle(blockEntity.getBlockState());

ModelRegistry.prepForBER(stack, blockEntity);
stack.translate(0, 0.25f, 0);
stack.translate(0.5+(0.015625), 0.125, 0.5-(0.015625));

var model = ModelRegistry.get(blockEntity, "block");
var scale = model.renderObject.scale * 0.5f;
stack.scale(scale, scale, scale);
primeInstance.viewMatrix().set(stack.last().pose());
stack.mulPose(Axis.YP.rotationDegrees(angle));
// stack.scale(1);

model.render(primeInstance, RenderSystem.getProjectionMatrix());
Minecraft.getInstance().getItemRenderer().renderStatic(block.ball(), ItemDisplayContext.GROUND, packedLight, packedLight, stack, buffer, blockEntity.getLevel(), 0);
stack.popPose();
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package generations.gg.generations.core.generationscore.world.level.block;

import com.cobblemon.mod.common.api.pokeball.PokeBalls;
import generations.gg.generations.core.generationscore.GenerationsCore;
import generations.gg.generations.core.generationscore.world.level.block.entities.BallLootBlockEntity;
import generations.gg.generations.core.generationscore.world.level.block.entities.BallLootBlockEntity.LootMode;
Expand All @@ -23,6 +24,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -31,6 +33,7 @@
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
Expand All @@ -42,10 +45,12 @@ public class BallLootBlock extends GenericRotatableModelBlock<BallLootBlockEntit
private static VoxelShape shape = Shapes.box(0.25f, 0.0f, 0.25f, 0.75, 0.5f, 0.75f);
private final String name;
private final ResourceLocation lootTable;
private final ResourceLocation ball;

protected BallLootBlock(String name, Properties properties) {
super(properties, GenerationsBlockEntities.BALL_LOOT, GenerationsBlockEntityModels.POKEBALL);
this.name = name;
this.ball = new ResourceLocation("cobblemon", name + "_ball");
this.lootTable = GenerationsCore.id("chests/%s_ball".formatted(name));
}

Expand Down Expand Up @@ -168,4 +173,15 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L
super.setPlacedBy(level, pos, state, placer, stack);
if(level.getBlockEntity(pos) instanceof BallLootBlockEntity lootBlockEntity && placer instanceof ServerPlayer player) lootBlockEntity.setOwner(placer.getUUID());
}

public ItemStack ball() {
var ball = PokeBalls.INSTANCE.getPokeBall(this.ball);

return (ball != null ? ball : PokeBalls.INSTANCE.getPOKE_BALL()).stack(1);
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return shape;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.*;
import java.util.stream.Collectors;

public class BallLootBlockEntity extends ModelProvidingBlockEntity implements ModelContextProviders.VariantProvider {
public class BallLootBlockEntity extends ModelProvidingBlockEntity {
private UUID owner = null;
private final List<LootClaim> claims = new ArrayList<>();
private LootMode lootMode = LootMode.ONCE_PER_PLAYER;
Expand Down Expand Up @@ -72,10 +72,10 @@ public BallLootBlockEntity(BlockPos pPos, BlockState pBlockState) {
super(GenerationsBlockEntities.BALL_LOOT.get(), pPos, pBlockState);
}

@Override
public String getVariant() {
return getBlockState().getBlock() instanceof BallLootBlock loot ? loot.getType() : "poke";
}
// @Override
// public String getVariant() {
// return getBlockState().getBlock() instanceof BallLootBlock loot ? loot.getType() : "poke";
// }

public UUID getOwner() {
return owner;
Expand Down

0 comments on commit 889afbb

Please sign in to comment.