Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Meatball Arcane (A furniture AND magic addition) #58

Merged
merged 3 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ to this README.md, then you will be asked to add to it. If you continue failing
- Soulstealer armor
- Processing Tool
- Magnet
- A Meatball and Ikea Furniture Based Arcane System
9 changes: 9 additions & 0 deletions src/main/java/io/github/communitymod/client/ClientEvents.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.communitymod.client;

import io.github.communitymod.CommunityMod;
import io.github.communitymod.client.blockentity.renderer.MeatballChaliceRenderer;
import io.github.communitymod.client.entity.bean.BeanModel;
import io.github.communitymod.client.entity.bean.BeanRenderer;
import io.github.communitymod.client.entity.extremetnt.ExtremeTntRenderer;
Expand All @@ -9,8 +10,13 @@
import io.github.communitymod.client.entity.meatball.MeatballRenderer;
import io.github.communitymod.client.entity.stick.ThrownStickEntityRenderer;
import io.github.communitymod.client.entity.wolf.WolfStickRenderLayer;
import io.github.communitymod.core.init.BlockEntityInit;
import io.github.communitymod.core.init.BlockInit;
import io.github.communitymod.core.init.EntityInit;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.entity.WolfRenderer;
import net.minecraft.world.entity.EntityType;
Expand All @@ -35,6 +41,9 @@ public static final class ModEvents {
@SubscribeEvent
public static void clientSetup(final FMLClientSetupEvent event) {

BlockEntityRenderers.register(BlockEntityInit.MEATBALL_CHALICE_BE.get(), MeatballChaliceRenderer::new);
ItemBlockRenderTypes.setRenderLayer(BlockInit.GLASS_TABLE.get(), RenderType.translucent());

}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.github.communitymod.client.blockentity.renderer;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Quaternion;

import io.github.communitymod.common.block_entities.MeatballChaliceBlockEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.item.ItemStack;

public class MeatballChaliceRenderer implements BlockEntityRenderer<MeatballChaliceBlockEntity> {

public MeatballChaliceRenderer(BlockEntityRendererProvider.Context context) {
}

@Override
public void render(MeatballChaliceBlockEntity pBlockEntity, float pPartialTicks, PoseStack stack,
MultiBufferSource pBuffer, int pCombinedLight, int pCombinedOverlay) {

ItemStack item = pBlockEntity.getItem();

if (!item.isEmpty()) {
stack.pushPose();

float f = 1.5f;
stack.scale(f, f, f);
stack.translate(0.41, 0.75f, 0.3333);
stack.mulPose(new Quaternion(0, 0, 45, true));

Minecraft.getInstance().getItemRenderer().render(item, TransformType.GROUND, false, stack, pBuffer,
pCombinedLight, pCombinedOverlay,
Minecraft.getInstance().getItemRenderer().getModel(item, pBlockEntity.getLevel(), null, 0));
stack.popPose();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ public void render(Meatball pEntity, float pEntityYaw, float pPartialTicks, Pose

VertexConsumer vertexconsumer = pBuffer.getBuffer(RenderType.entityCutoutNoCull(TEXTURE));

this.meatball.xRot += pEntity.getDeltaMovement().x;
this.meatball.yRot += pEntity.getDeltaMovement().y;
this.meatball.zRot += pEntity.getDeltaMovement().z;

this.meatball.xRot += pEntity.getDeltaMovement().x / 1.3;
this.meatball.yRot += pEntity.getDeltaMovement().y / 1.3;
this.meatball.zRot += pEntity.getDeltaMovement().z / 1.3;

if (pEntity.isLarge()) {
pMatrixStack.scale(4, 4, 4);
this.meatball.xRot /= 2f;
this.meatball.yRot /= 2f;
this.meatball.zRot /= 2f;
}
this.meatball.render(pMatrixStack, vertexconsumer, pPackedLight, OverlayTexture.NO_OVERLAY);

super.render(pEntity, pEntityYaw, pPartialTicks, pMatrixStack, pBuffer, pPackedLight);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package io.github.communitymod.common.block_entities;

import java.util.HashMap;

import javax.annotation.Nullable;

import io.github.communitymod.common.blocks.MeatballChalice;
import io.github.communitymod.common.blocks.ikeafurniture.IkeaFurniture;
import io.github.communitymod.core.init.BlockEntityInit;
import io.github.communitymod.core.util.MeatballTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
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.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;

public class MeatballChaliceBlockEntity extends BaseContainerBlockEntity {

protected int timer = 0;

protected NonNullList<ItemStack> item = NonNullList.withSize(1, ItemStack.EMPTY);

public MeatballChaliceBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) {
super(BlockEntityInit.MEATBALL_CHALICE_BE.get(), pWorldPosition, pBlockState);
}

public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, MeatballChaliceBlockEntity bE) {

if (bE.getTimer() > 0) {
bE.timer--;
bE.setChanged();
}

if (bE.isEmpty())
bE.timer = 0;

if (bE.getBlockState().getValue(MeatballChalice.IS_GLOWING) != bE.getTimer() > 0)
pLevel.setBlock(pPos, pState.setValue(MeatballChalice.IS_GLOWING, bE.getTimer() > 0), 2);

if (bE.timer == 1) {
if (bE.selectTargetBlock(pLevel, pPos) != null) {
bE.getItem().getOrCreateTag().putBoolean(bE.selectTargetBlock(pLevel, pPos).toString(), true);

}
}
}

@Nullable
private MeatballTypes selectTargetBlock(Level pLevel, BlockPos pPos) {

HashMap<BlockPos, IkeaFurniture> validBlocks = new HashMap<>();

for (int x = pPos.getX() - 4; x < pPos.getX() + 4; x++) {
for (int y = pPos.getY() - 3; y < pPos.getY() + 3; y++) {
for (int z = pPos.getZ() - 4; z < pPos.getZ() + 4; z++) {

BlockPos pos = new BlockPos(x, y, z);
Block block = pLevel.getBlockState(pos).getBlock();

if (block instanceof IkeaFurniture) {
validBlocks.put(pos, (IkeaFurniture) block);
}

}
}
}

validBlocks.entrySet().stream()
.sorted((x, y) -> Double.compare(x.getKey().distSqr(pPos, true), y.getKey().distSqr(pPos, true)));

if (!validBlocks.isEmpty()) {
return validBlocks.entrySet().stream().findFirst().get().getValue().getAttribute();
} else
return null;
}

public ItemStack getItem() {
return item.get(0);
}

public int getTimer() {
return timer;
}

public void setTimer(int timer) {
this.timer = timer;
}

public CompoundTag save(CompoundTag pCompound) {
super.save(pCompound);
ContainerHelper.saveAllItems(pCompound, this.item);
pCompound.putInt("timer", timer);

return pCompound;
}

public void load(CompoundTag pTag) {

super.load(pTag);
this.item = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);

this.timer = pTag.getInt("timer");

ContainerHelper.loadAllItems(pTag, this.item);
}

public void setItem(ItemStack stack) {
item.set(0, stack);
this.setChanged();
}

@Override
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return new ClientboundBlockEntityDataPacket(worldPosition, -1, getUpdateTag());
}

@Override
public CompoundTag getUpdateTag() {
return this.save(new CompoundTag());
}

@Override
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
load(pkt.getTag());
}

@Override
public int getContainerSize() {
return 1;
}

@Override
protected Component getDefaultName() {
return new TextComponent("block.communitymod.meatball_chalice");
}

@Override
protected AbstractContainerMenu createMenu(int pContainerId, Inventory pInventory) {
return null;
}

@Override
public boolean isEmpty() {
return getItem(0).isEmpty();
}

@Override
public ItemStack getItem(int pIndex) {
return getItem();
}

@Override
public ItemStack removeItem(int pIndex, int pCount) {
this.setChanged();

getItem(pIndex).shrink(pCount);

return getItem();
}

@Override
public ItemStack removeItemNoUpdate(int pIndex) {
return null;
}

@Override
public void setItem(int pIndex, ItemStack pStack) {
item.set(pIndex, pStack);
this.setChanged();
}

@Override
public boolean stillValid(Player pPlayer) {
return true;
}

@Override
public void clearContent() {
this.item.clear();
this.setChanged();
}

}

This file was deleted.