generated from neoforged/MDK
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
554613d
commit 0f109ea
Showing
15 changed files
with
204 additions
and
74 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
src/generated/resources/.cache/14206c24fc2e930dba0bbfc365944e11303961ec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/generated/resources/data/bibliocraft/tags/items/cookie_jar_cookies.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"values": [ | ||
"minecraft:cookie" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/com/github/minecraftschurlimods/bibliocraft/client/ber/CookieJarBER.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.github.minecraftschurlimods.bibliocraft.client.ber; | ||
|
||
import com.github.minecraftschurlimods.bibliocraft.content.cookiejar.CookieJarBlockEntity; | ||
import com.github.minecraftschurlimods.bibliocraft.init.BCTags; | ||
import com.github.minecraftschurlimods.bibliocraft.util.ClientUtil; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.math.Axis; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.levelgen.LegacyRandomSource; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
|
||
public class CookieJarBER implements BlockEntityRenderer<CookieJarBlockEntity> { | ||
private final RandomSource random = new LegacyRandomSource(0); | ||
|
||
@SuppressWarnings("unused") | ||
public CookieJarBER(BlockEntityRendererProvider.Context context) { | ||
} | ||
|
||
@Override | ||
public void render(CookieJarBlockEntity blockEntity, float partialTick, PoseStack stack, MultiBufferSource buffer, int light, int overlay) { | ||
List<ItemStack> items = IntStream.rangeClosed(0, blockEntity.getContainerSize() - 1) | ||
.mapToObj(blockEntity::getItem) | ||
.filter(e -> !e.isEmpty()) | ||
.toList(); | ||
List<ItemStack> cookies = BuiltInRegistries.ITEM.getTag(BCTags.Items.COOKIE_JAR_COOKIES) | ||
.orElseThrow() | ||
.stream() | ||
.sorted(Comparator.comparing(a -> BuiltInRegistries.ITEM.getKey(a.value()))) | ||
.map(ItemStack::new) | ||
.toList(); | ||
random.setSeed(blockEntity.getBlockPos().asLong()); | ||
stack.translate(0.5, 0.5, 0.5); | ||
for (int i = 0; i < items.size(); i++) { | ||
ItemStack item = items.get(i); | ||
ItemStack cookie = cookies.get(random.nextInt(cookies.size())); | ||
stack.pushPose(); | ||
cookiePosition(i, stack); | ||
ClientUtil.renderFixedItem(item.is(BCTags.Items.COOKIE_JAR_COOKIES) ? item : cookie, stack, buffer, light, overlay); | ||
stack.popPose(); | ||
} | ||
} | ||
|
||
private void cookiePosition(int index, PoseStack stack) { | ||
switch (index) { | ||
case 0: | ||
stack.translate(-0.1, -0.425, 0.1); | ||
break; | ||
case 1: | ||
stack.translate(-0.0875, -0.3875, -0.0875); | ||
stack.mulPose(Axis.XP.rotationDegrees(-15)); | ||
break; | ||
case 2: | ||
stack.translate(0.1, -0.3325, 0); | ||
stack.mulPose(Axis.ZP.rotationDegrees(-20)); | ||
break; | ||
case 3: | ||
stack.translate(0.1, -0.295, -0.125); | ||
stack.mulPose(Axis.XP.rotationDegrees(-15)); | ||
stack.mulPose(Axis.ZP.rotationDegrees(-15)); | ||
break; | ||
case 4: | ||
stack.translate(-0.1, -0.245, 0.15); | ||
stack.mulPose(Axis.XP.rotationDegrees(35)); | ||
stack.mulPose(Axis.YP.rotationDegrees(180)); | ||
break; | ||
case 5: | ||
stack.translate(-0.1, -0.1625, -0.125); | ||
stack.mulPose(Axis.XP.rotationDegrees(-30)); | ||
stack.mulPose(Axis.ZP.rotationDegrees(5)); | ||
break; | ||
case 6: | ||
stack.translate(-0.1, -0.1325, 0.1575); | ||
stack.mulPose(Axis.XP.rotationDegrees(45)); | ||
stack.mulPose(Axis.ZP.rotationDegrees(10)); | ||
stack.mulPose(Axis.YP.rotationDegrees(180)); | ||
break; | ||
case 7: | ||
stack.translate(0.2, -0.125, 0.1); | ||
stack.mulPose(Axis.XP.rotationDegrees(30)); | ||
stack.mulPose(Axis.ZP.rotationDegrees(-60)); | ||
stack.mulPose(Axis.YP.rotationDegrees(-105)); | ||
break; | ||
} | ||
stack.mulPose(Axis.XP.rotationDegrees(90)); | ||
stack.scale(0.6f, 0.6f, 0.6f); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
...main/java/com/github/minecraftschurlimods/bibliocraft/util/content/BCBaseEntityBlock.java
This file was deleted.
Oops, something went wrong.
43 changes: 39 additions & 4 deletions
43
src/main/java/com/github/minecraftschurlimods/bibliocraft/util/content/BCEntityBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,73 @@ | ||
package com.github.minecraftschurlimods.bibliocraft.util.content; | ||
|
||
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.Container; | ||
import net.minecraft.world.Containers; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.MenuProvider; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.EntityBlock; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.material.PushReaction; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Abstract superclass for non-rotatable entity blocks in this mod. | ||
*/ | ||
@SuppressWarnings({"deprecation", "DuplicatedCode"}) | ||
public abstract class BCEntityBlock extends BCWaterloggedBlock implements BCBaseEntityBlock { | ||
public abstract class BCEntityBlock extends BCWaterloggedBlock implements EntityBlock { | ||
public BCEntityBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
public PushReaction getPistonPushReaction(BlockState state) { | ||
return PushReaction.BLOCK; | ||
} | ||
|
||
@Override | ||
public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) { | ||
BCBaseEntityBlock.super.setPlacedBy(level, pos, state, entity, stack, () -> super.setPlacedBy(level, pos, state, entity, stack)); | ||
super.setPlacedBy(level, pos, state, entity, stack); | ||
if (level.getBlockEntity(pos) instanceof BCMenuBlockEntity blockEntity && stack.hasCustomHoverName()) { | ||
blockEntity.setCustomName(stack.getHoverName()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean flag) { | ||
BCBaseEntityBlock.super.onRemove(state, level, pos, newState, flag, this, () -> super.onRemove(state, level, pos, newState, flag)); | ||
if (!state.is(newState.getBlock())) { | ||
BlockEntity blockentity = level.getBlockEntity(pos); | ||
if (blockentity instanceof Container container) { | ||
Containers.dropContents(level, pos, container); | ||
level.updateNeighbourForOutputSignal(pos, this); | ||
} | ||
super.onRemove(state, level, pos, newState, flag); | ||
} | ||
} | ||
|
||
@Override | ||
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { | ||
return player.isSecondaryUseActive() ? InteractionResult.PASS : BCUtil.openBEMenu(player, level, pos); | ||
} | ||
|
||
@Override | ||
public boolean triggerEvent(BlockState state, Level level, BlockPos pos, int id, int param) { | ||
return BCBaseEntityBlock.super.triggerEvent(state, level, pos, id, param, () -> super.triggerEvent(state, level, pos, id, param)); | ||
super.triggerEvent(state, level, pos, id, param); | ||
BlockEntity blockentity = level.getBlockEntity(pos); | ||
return blockentity != null && blockentity.triggerEvent(id, param); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public MenuProvider getMenuProvider(BlockState state, Level level, BlockPos pos) { | ||
BlockEntity blockentity = level.getBlockEntity(pos); | ||
return blockentity instanceof MenuProvider ? (MenuProvider) blockentity : null; | ||
} | ||
} |
Oops, something went wrong.