a few puter fixes
This commit is contained in:
1 parent
c27e68c16a
commit
0c400ef404
9 files changed
+112
-39
No files matched your search
+10
-1
@@ -19,16 +19,20 @@ import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
|||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||||
|
|
||||||
public final class ComputerBlock extends BaseEntityBlock {
|
public final class ComputerBlock extends BaseEntityBlock {
|
||||||
public static final MapCodec<ComputerBlock> CODEC = Block.simpleCodec(ComputerBlock::new);
|
public static final MapCodec<ComputerBlock> CODEC = Block.simpleCodec(ComputerBlock::new);
|
||||||
|
public static final BooleanProperty ACTIVE = BooleanProperty.create("active");
|
||||||
private static final VoxelShape SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 16.0D, 15.0D);
|
private static final VoxelShape SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 16.0D, 15.0D);
|
||||||
|
|
||||||
public ComputerBlock(BlockBehaviour.Properties properties) {
|
public ComputerBlock(BlockBehaviour.Properties properties) {
|
||||||
super(properties);
|
super(properties.lightLevel(state -> state.getValue(ACTIVE) ? 7 : 0));
|
||||||
|
registerDefaultState(stateDefinition.any().setValue(ACTIVE, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -36,6 +40,11 @@ public final class ComputerBlock extends BaseEntityBlock {
|
|||||||
return CODEC;
|
return CODEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||||
|
builder.add(ACTIVE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RenderShape getRenderShape(BlockState state) {
|
protected RenderShape getRenderShape(BlockState state) {
|
||||||
return RenderShape.ENTITYBLOCK_ANIMATED;
|
return RenderShape.ENTITYBLOCK_ANIMATED;
|
||||||
|
|||||||
+14
-1
@@ -1,6 +1,7 @@
|
|||||||
package com.craisinlord.antarchy.content.block.entity;
|
package com.craisinlord.antarchy.content.block.entity;
|
||||||
|
|
||||||
import com.craisinlord.antarchy.content.AntarchyObjects;
|
import com.craisinlord.antarchy.content.AntarchyObjects;
|
||||||
|
import com.craisinlord.antarchy.content.block.ComputerBlock;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
@@ -14,6 +15,7 @@ import net.minecraft.world.level.Level;
|
|||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@@ -46,6 +48,9 @@ public final class ComputerBlockEntity extends BlockEntity implements GeoBlockEn
|
|||||||
|
|
||||||
public static void tick(Level level, BlockPos pos, BlockState state, ComputerBlockEntity computer) {
|
public static void tick(Level level, BlockPos pos, BlockState state, ComputerBlockEntity computer) {
|
||||||
boolean active = computer.isActive();
|
boolean active = computer.isActive();
|
||||||
|
if (!level.isClientSide && state.getValue(ComputerBlock.ACTIVE) != active) {
|
||||||
|
level.setBlock(pos, state.setValue(ComputerBlock.ACTIVE, active), 3);
|
||||||
|
}
|
||||||
if (active != computer.lastActive) {
|
if (active != computer.lastActive) {
|
||||||
computer.lastActive = active;
|
computer.lastActive = active;
|
||||||
computer.triggerAnim("transitions", active ? "turn_on" : "turn_off");
|
computer.triggerAnim("transitions", active ? "turn_on" : "turn_off");
|
||||||
@@ -80,13 +85,21 @@ public final class ComputerBlockEntity extends BlockEntity implements GeoBlockEn
|
|||||||
public void activate() {
|
public void activate() {
|
||||||
if (level != null && !level.isClientSide) {
|
if (level != null && !level.isClientSide) {
|
||||||
activeUntil = Math.max(activeUntil, level.getGameTime() + 40L);
|
activeUntil = Math.max(activeUntil, level.getGameTime() + 40L);
|
||||||
|
if (!getBlockState().getValue(ComputerBlock.ACTIVE)) {
|
||||||
|
level.setBlock(worldPosition, getBlockState().setValue(ComputerBlock.ACTIVE, true), 3);
|
||||||
|
}
|
||||||
setChanged();
|
setChanged();
|
||||||
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 3);
|
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return level != null && (level.hasNeighborSignal(worldPosition) || level.getGameTime() < activeUntil);
|
return level != null && (level.hasNeighborSignal(worldPosition) || level.getGameTime() < activeUntil || hasNearbyPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasNearbyPlayer() {
|
||||||
|
Vec3 center = Vec3.atCenterOf(worldPosition);
|
||||||
|
return level.players().stream().anyMatch(player -> player.distanceToSqr(center) <= 25.0D);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+5
-1
@@ -6,6 +6,7 @@ import com.craisinlord.antarchy.content.guide.ComputerGuideData;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiGraphics;
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
|
import net.minecraft.client.gui.components.Renderable;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.util.FormattedCharSequence;
|
import net.minecraft.util.FormattedCharSequence;
|
||||||
@@ -66,6 +67,7 @@ public final class ComputerScreen extends Screen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
|
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
|
||||||
|
super.render(graphics, mouseX, mouseY, partialTick);
|
||||||
int left = (this.width - WIDTH) / 2;
|
int left = (this.width - WIDTH) / 2;
|
||||||
int top = (this.height - HEIGHT) / 2;
|
int top = (this.height - HEIGHT) / 2;
|
||||||
graphics.fill(0, 0, this.width, this.height, 0x99000000);
|
graphics.fill(0, 0, this.width, this.height, 0x99000000);
|
||||||
@@ -94,7 +96,9 @@ public final class ComputerScreen extends Screen {
|
|||||||
} else {
|
} else {
|
||||||
renderEntry(graphics, visibleEntries.get(selectedIndex), left + 124, top + 62, accent);
|
renderEntry(graphics, visibleEntries.get(selectedIndex), left + 124, top + 62, accent);
|
||||||
}
|
}
|
||||||
super.render(graphics, mouseX, mouseY, partialTick);
|
for (Renderable renderable : this.renderables) {
|
||||||
|
renderable.render(graphics, mouseX, mouseY, partialTick);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderEntry(GuiGraphics graphics, ComputerGuideData.Entry entry, int x, int y, int accent) {
|
private void renderEntry(GuiGraphics graphics, ComputerGuideData.Entry entry, int x, int y, int accent) {
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.craisinlord.antarchy.content.item;
|
||||||
|
|
||||||
|
import com.craisinlord.antarchy.content.client.model.ResourceBackedGeoItemModel;
|
||||||
|
import com.craisinlord.antarchy.content.client.renderer.AnimatedHeldItemRenderer;
|
||||||
|
import com.craisinlord.antarchy.content.block.ComputerBlock;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.item.BlockItem;
|
||||||
|
import software.bernie.geckolib.animatable.GeoItem;
|
||||||
|
import software.bernie.geckolib.animatable.client.GeoRenderProvider;
|
||||||
|
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
|
||||||
|
import software.bernie.geckolib.animation.AnimatableManager;
|
||||||
|
import software.bernie.geckolib.animation.AnimationController;
|
||||||
|
import software.bernie.geckolib.animation.PlayState;
|
||||||
|
import software.bernie.geckolib.animation.RawAnimation;
|
||||||
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public final class ComputerItem extends BlockItem implements GeoItem {
|
||||||
|
private static final ResourceLocation MODEL = ResourceLocation.fromNamespaceAndPath("antarchy", "geo/computer.geo.json");
|
||||||
|
private static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath("antarchy", "textures/block/computer/computer.png");
|
||||||
|
private static final ResourceLocation ANIMATION = ResourceLocation.fromNamespaceAndPath("antarchy", "animations/computer.animation.json");
|
||||||
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
|
|
||||||
|
public ComputerItem(ComputerBlock block, Properties properties) {
|
||||||
|
super(block, properties);
|
||||||
|
GeoItem.registerSyncedAnimatable(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
|
||||||
|
controllers.add(new AnimationController<>(this, "state", state -> state.setAndContinue(RawAnimation.begin().thenLoop("off_state"))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AnimatableInstanceCache getAnimatableInstanceCache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createGeoRenderer(Consumer<GeoRenderProvider> consumer) {
|
||||||
|
consumer.accept(new GeoRenderProvider() {
|
||||||
|
private AnimatedHeldItemRenderer<ComputerItem> renderer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer getGeoItemRenderer() {
|
||||||
|
if (renderer == null) {
|
||||||
|
renderer = new AnimatedHeldItemRenderer<>(new ResourceBackedGeoItemModel<>(MODEL, TEXTURE, ANIMATION));
|
||||||
|
}
|
||||||
|
return renderer;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,29 @@
|
|||||||
{
|
{
|
||||||
"type": "minecraft:crafting_shapeless",
|
"type": "minecraft:crafting_shaped",
|
||||||
"ingredients": [
|
"key": {
|
||||||
{"item": "minecraft:iron_block"},
|
"A": {
|
||||||
{"item": "minecraft:iron_block"},
|
"item": "minecraft:iron_ingot"
|
||||||
{"item": "minecraft:iron_block"},
|
},
|
||||||
{"item": "minecraft:comparator"},
|
"B": {
|
||||||
{"item": "minecraft:iron_ingot"}
|
"item": "minecraft:copper_ingot"
|
||||||
|
},
|
||||||
|
"C": {
|
||||||
|
"item": "minecraft:tinted_glass"
|
||||||
|
},
|
||||||
|
"D": {
|
||||||
|
"item": "minecraft:comparator"
|
||||||
|
},
|
||||||
|
"E": {
|
||||||
|
"item": "antarchy:bluestone_comparator"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pattern": [
|
||||||
|
"AAC",
|
||||||
|
"DBE",
|
||||||
|
"AAA"
|
||||||
],
|
],
|
||||||
"result": {
|
"result": {
|
||||||
"id": "antarchy:computer",
|
"count": 1,
|
||||||
"count": 1
|
"id": "antarchy:computer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"type": "minecraft:crafting_shaped",
|
|
||||||
"pattern": [
|
|
||||||
"T N",
|
|
||||||
"TSN",
|
|
||||||
"TBT"
|
|
||||||
],
|
|
||||||
"key": {
|
|
||||||
"T": {
|
|
||||||
"item": "antarchy:titanium_ingot"
|
|
||||||
},
|
|
||||||
"N": {
|
|
||||||
"item": "antarchy:nightmare_scale"
|
|
||||||
},
|
|
||||||
"S": {
|
|
||||||
"item": "minecraft:nether_star"
|
|
||||||
},
|
|
||||||
"B": {
|
|
||||||
"item": "antarchy:bluestone_comparator"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"result": {
|
|
||||||
"id": "antarchy:portal_gun"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-1
@@ -100,7 +100,8 @@ public final class AntarchyFabricItems {
|
|||||||
|
|
||||||
|
|
||||||
public static final DeferredItem<net.minecraft.world.item.BlockItem> DUPLICATOR_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyFabricBlocks.DUPLICATOR_LOG);
|
public static final DeferredItem<net.minecraft.world.item.BlockItem> DUPLICATOR_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyFabricBlocks.DUPLICATOR_LOG);
|
||||||
public static final DeferredItem<net.minecraft.world.item.BlockItem> COMPUTER_ITEM = ITEMS.registerSimpleBlockItem(AntarchyFabricBlocks.COMPUTER);
|
public static final DeferredItem<ComputerItem> COMPUTER_ITEM = ITEMS.register("computer",
|
||||||
|
() -> new ComputerItem(AntarchyFabricBlocks.COMPUTER.get(), new Item.Properties()));
|
||||||
|
|
||||||
|
|
||||||
public static final DeferredItem<net.minecraft.world.item.BlockItem> OURANWOOD_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyFabricBlocks.OURANWOOD_LOG);
|
public static final DeferredItem<net.minecraft.world.item.BlockItem> OURANWOOD_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyFabricBlocks.OURANWOOD_LOG);
|
||||||
|
|||||||
+1
@@ -593,6 +593,7 @@ public final class AntarchyNeoForgeClient {
|
|||||||
registerGeoItemExtension(event, AntarchyNeoforgeItems.BATTLE_AXE.get());
|
registerGeoItemExtension(event, AntarchyNeoforgeItems.BATTLE_AXE.get());
|
||||||
registerGeoItemExtension(event, AntarchyNeoforgeItems.BIG_BERTHA.get());
|
registerGeoItemExtension(event, AntarchyNeoforgeItems.BIG_BERTHA.get());
|
||||||
registerGeoItemExtension(event, AntarchyNeoforgeItems.ROYAL_GUARDIAN_SWORD.get());
|
registerGeoItemExtension(event, AntarchyNeoforgeItems.ROYAL_GUARDIAN_SWORD.get());
|
||||||
|
registerGeoItemExtension(event, AntarchyNeoforgeItems.COMPUTER_ITEM.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
+2
-1
@@ -206,7 +206,8 @@ public final class AntarchyNeoforgeItems {
|
|||||||
|
|
||||||
// Block items
|
// Block items
|
||||||
public static final DeferredItem<net.minecraft.world.item.BlockItem> DUPLICATOR_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyNeoforgeBlocks.DUPLICATOR_LOG);
|
public static final DeferredItem<net.minecraft.world.item.BlockItem> DUPLICATOR_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyNeoforgeBlocks.DUPLICATOR_LOG);
|
||||||
public static final DeferredItem<net.minecraft.world.item.BlockItem> COMPUTER_ITEM = ITEMS.registerSimpleBlockItem(AntarchyNeoforgeBlocks.COMPUTER);
|
public static final DeferredItem<ComputerItem> COMPUTER_ITEM = ITEMS.register("computer",
|
||||||
|
() -> new ComputerItem(AntarchyNeoforgeBlocks.COMPUTER.get(), new Item.Properties()));
|
||||||
public static final DeferredItem<net.minecraft.world.item.BlockItem> OURANWOOD_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyNeoforgeBlocks.OURANWOOD_LOG);
|
public static final DeferredItem<net.minecraft.world.item.BlockItem> OURANWOOD_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyNeoforgeBlocks.OURANWOOD_LOG);
|
||||||
public static final DeferredItem<net.minecraft.world.item.BlockItem> OURANWOOD_WOOD_ITEM = ITEMS.registerSimpleBlockItem(AntarchyNeoforgeBlocks.OURANWOOD_WOOD);
|
public static final DeferredItem<net.minecraft.world.item.BlockItem> OURANWOOD_WOOD_ITEM = ITEMS.registerSimpleBlockItem(AntarchyNeoforgeBlocks.OURANWOOD_WOOD);
|
||||||
public static final DeferredItem<net.minecraft.world.item.BlockItem> MOSSY_OURANWOOD_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyNeoforgeBlocks.MOSSY_OURANWOOD_LOG);
|
public static final DeferredItem<net.minecraft.world.item.BlockItem> MOSSY_OURANWOOD_LOG_ITEM = ITEMS.registerSimpleBlockItem(AntarchyNeoforgeBlocks.MOSSY_OURANWOOD_LOG);
|
||||||
|
|||||||
Reference in new issue
Block a user