Skip to content

Commit

Permalink
Add models for grindstone and stonecutter, add chest and ender chest …
Browse files Browse the repository at this point in the history
…attachments, add launch gel
  • Loading branch information
FoundationGames committed May 19, 2022
1 parent cc14d3c commit 15754c8
Show file tree
Hide file tree
Showing 32 changed files with 2,874 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ myron_version=1.6.3+1.18.1
arrp_version=0.5.5
jsonem_version=0.1.2

mod_version = 0.0.11+1.18.2
mod_version = 0.0.12+1.18.2
maven_group = io.github.foundationgames
archives_base_name = automobility

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.foundationgames.automobility.automobile.attachment;

import io.github.foundationgames.automobility.Automobility;
import io.github.foundationgames.automobility.automobile.attachment.rear.BaseChestRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.EmptyRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.PassengerSeatRearAttachment;
import io.github.foundationgames.automobility.automobile.attachment.rear.RearAttachment;
Expand Down Expand Up @@ -35,9 +36,11 @@ public record RearAttachmentType<T extends RearAttachment>(
public static final RearAttachmentType<BlockRearAttachment> LOOM = register(block("loom", BlockRearAttachment::loom));
public static final RearAttachmentType<BlockRearAttachment> CARTOGRAPHY_TABLE = register(block("cartography_table", BlockRearAttachment::cartographyTable));
public static final RearAttachmentType<BlockRearAttachment> SMITHING_TABLE = register(block("smithing_table", BlockRearAttachment::smithingTable));
public static final RearAttachmentType<BlockRearAttachment> GRINDSTONE = register(block("grindstone", BlockRearAttachment::grindstone));
public static final RearAttachmentType<BlockRearAttachment> STONECUTTER = register(block("stonecutter", BlockRearAttachment::stonecutter));
public static final RearAttachmentType<BlockRearAttachment> GRINDSTONE = register(block("grindstone", Automobility.id("rearatt_grindstone"), BlockRearAttachment::grindstone));
public static final RearAttachmentType<BlockRearAttachment> STONECUTTER = register(block("stonecutter", Automobility.id("rearatt_stonecutter"), BlockRearAttachment::stonecutter));

public static final RearAttachmentType<BlockRearAttachment> CHEST = register(chest("chest", BaseChestRearAttachment::chest));
public static final RearAttachmentType<BlockRearAttachment> ENDER_CHEST = register(chest("ender_chest", BaseChestRearAttachment::enderChest));

public boolean isEmpty() {
return this == EMPTY;
Expand All @@ -48,10 +51,18 @@ public Identifier getId() {
return this.id;
}

private static RearAttachmentType<BlockRearAttachment> chest(String name, BiFunction<RearAttachmentType<BlockRearAttachment>, AutomobileEntity, BlockRearAttachment> constructor) {
return block(name, Automobility.id("rearatt_chest"), constructor);
}

private static RearAttachmentType<BlockRearAttachment> block(String name, BiFunction<RearAttachmentType<BlockRearAttachment>, AutomobileEntity, BlockRearAttachment> constructor) {
return block(name, Automobility.id("rearatt_block"), constructor);
}

private static RearAttachmentType<BlockRearAttachment> block(String name, Identifier model, BiFunction<RearAttachmentType<BlockRearAttachment>, AutomobileEntity, BlockRearAttachment> constructor) {
return new RearAttachmentType<>(
Automobility.id(name), constructor,
new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/"+name+".png"), Automobility.id("rearatt_block"), 11)
new RearAttachmentModel(Automobility.id("textures/entity/automobile/rear_attachment/"+name+".png"), model, 11)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package io.github.foundationgames.automobility.automobile.attachment.rear;

import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import io.github.foundationgames.automobility.util.duck.EnderChestInventoryDuck;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.ChestLidAnimator;
import net.minecraft.block.entity.ViewerCountManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.function.BiFunction;

public class BaseChestRearAttachment extends BlockRearAttachment {
public static final Text TITLE_CHEST = new TranslatableText("container.chest");
public static final Text TITLE_ENDER_CHEST = new TranslatableText("container.enderchest");

private final ViewerCountManager stateManager;
private final ChestLidAnimator lidAnimator;

public BaseChestRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity, BlockState block, @Nullable BiFunction<ScreenHandlerContext, BlockRearAttachment, NamedScreenHandlerFactory> screenProvider) {
super(type, entity, block, screenProvider);
this.stateManager = new ViewerCountManager() {
protected void onContainerOpen(World world, BlockPos pos, BlockState state) {
sound(world, pos, BaseChestRearAttachment.this.getOpenSound());
}

protected void onContainerClose(World world, BlockPos pos, BlockState state) {
sound(world, pos, BaseChestRearAttachment.this.getCloseSound());
}

protected void onViewerCountUpdate(World world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) {}

protected boolean isPlayerViewing(PlayerEntity player) {
if (!(player.currentScreenHandler instanceof GenericContainerScreenHandler)) {
return false;
} else {
var inventory = ((GenericContainerScreenHandler)player.currentScreenHandler).getInventory();
return inventory == BaseChestRearAttachment.this;
}
}
};
this.lidAnimator = new ChestLidAnimator();
}

public void open(PlayerEntity player) {
if (!player.isSpectator()) {
this.stateManager.openContainer(player, this.world(), this.automobile.getBlockPos(), Blocks.AIR.getDefaultState());
}
}

public void close(PlayerEntity player) {
if (!player.isSpectator()) {
this.stateManager.closeContainer(player, this.world(), this.automobile.getBlockPos(), Blocks.AIR.getDefaultState());
}
}

protected SoundEvent getOpenSound() {
return SoundEvents.BLOCK_ENDER_CHEST_OPEN;
}

protected SoundEvent getCloseSound() {
return SoundEvents.BLOCK_ENDER_CHEST_CLOSE;
}

private static void sound(World world, BlockPos pos, SoundEvent soundEvent) {
world.playSound(null, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, soundEvent, SoundCategory.BLOCKS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
}

public static BaseChestRearAttachment chest(RearAttachmentType<?> type, AutomobileEntity entity) {
return new ChestRearAttachment(type, entity,
Blocks.ENDER_CHEST.getDefaultState(),
(ctx, att) -> att instanceof ChestRearAttachment chest ? chest : null);
}

public static BaseChestRearAttachment enderChest(RearAttachmentType<?> type, AutomobileEntity entity) {
return new BaseChestRearAttachment(type, entity,
Blocks.ENDER_CHEST.getDefaultState(),
(ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) -> {
var enderChest = player.getEnderChestInventory();
if (att instanceof BaseChestRearAttachment chest) {
EnderChestInventoryDuck.of(enderChest).automobility$setActiveAttachment(chest);
}
return GenericContainerScreenHandler.createGeneric9x3(syncId, inventory, enderChest);
}, TITLE_ENDER_CHEST)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import io.github.foundationgames.automobility.util.duck.EnderChestInventoryDuck;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.screen.CartographyTableScreenHandler;
import net.minecraft.screen.CraftingScreenHandler;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.GrindstoneScreenHandler;
import net.minecraft.screen.LoomScreenHandler;
import net.minecraft.screen.NamedScreenHandlerFactory;
Expand All @@ -17,6 +19,7 @@
import net.minecraft.text.TranslatableText;
import org.jetbrains.annotations.Nullable;

import java.util.function.BiFunction;
import java.util.function.Function;

public class BlockRearAttachment extends RearAttachment {
Expand All @@ -28,9 +31,9 @@ public class BlockRearAttachment extends RearAttachment {
public static final Text TITLE_STONECUTTER = new TranslatableText("container.stonecutter");

public final BlockState block;
private final @Nullable Function<ScreenHandlerContext, NamedScreenHandlerFactory> screenProvider;
private final @Nullable BiFunction<ScreenHandlerContext, BlockRearAttachment, NamedScreenHandlerFactory> screenProvider;

public BlockRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity, BlockState block, @Nullable Function<ScreenHandlerContext, NamedScreenHandlerFactory> screenProvider) {
public BlockRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity, BlockState block, @Nullable BiFunction<ScreenHandlerContext, BlockRearAttachment, NamedScreenHandlerFactory> screenProvider) {
super(type, entity);
this.block = block;
this.screenProvider = screenProvider;
Expand All @@ -43,54 +46,56 @@ public boolean hasMenu() {

@Override
public @Nullable NamedScreenHandlerFactory createMenu(ScreenHandlerContext ctx) {
return this.screenProvider != null ? this.screenProvider.apply(ctx) : null;
return this.screenProvider != null ? this.screenProvider.apply(ctx, this) : null;
}

public static BlockRearAttachment craftingTable(RearAttachmentType<?> type, AutomobileEntity entity) {
return new BlockRearAttachment(type, entity,
Blocks.CRAFTING_TABLE.getDefaultState(),
ctx -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
(ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
new CraftingScreenHandler(syncId, inventory, ctx), TITLE_CRAFTING)
);
}

public static BlockRearAttachment loom(RearAttachmentType<?> type, AutomobileEntity entity) {
return new BlockRearAttachment(type, entity,
Blocks.LOOM.getDefaultState(),
ctx -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
(ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
new LoomScreenHandler(syncId, inventory, ctx), TITLE_LOOM)
);
}

public static BlockRearAttachment cartographyTable(RearAttachmentType<?> type, AutomobileEntity entity) {
return new BlockRearAttachment(type, entity,
Blocks.CARTOGRAPHY_TABLE.getDefaultState(),
ctx -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
(ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
new CartographyTableScreenHandler(syncId, inventory, ctx), TITLE_CARTOGRAPHY)
);
}

public static BlockRearAttachment smithingTable(RearAttachmentType<?> type, AutomobileEntity entity) {
return new BlockRearAttachment(type, entity,
Blocks.SMITHING_TABLE.getDefaultState(),
ctx -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
(ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
new SmithingScreenHandler(syncId, inventory, ctx), TITLE_SMITHING)
);
}

public static BlockRearAttachment grindstone(RearAttachmentType<?> type, AutomobileEntity entity) {
return new BlockRearAttachment(type, entity,
Blocks.GRINDSTONE.getDefaultState(),
ctx -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
(ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
new GrindstoneScreenHandler(syncId, inventory, ctx), TITLE_GRINDSTONE)
);
}

public static BlockRearAttachment stonecutter(RearAttachmentType<?> type, AutomobileEntity entity) {
return new BlockRearAttachment(type, entity,
Blocks.STONECUTTER.getDefaultState(),
ctx -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
(ctx, att) -> new SimpleNamedScreenHandlerFactory((syncId, inventory, player) ->
new StonecutterScreenHandler(syncId, inventory, ctx), TITLE_STONECUTTER)
);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package io.github.foundationgames.automobility.automobile.attachment.rear;

import io.github.foundationgames.automobility.automobile.attachment.RearAttachmentType;
import io.github.foundationgames.automobility.entity.AutomobileEntity;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventories;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.collection.DefaultedList;
import org.jetbrains.annotations.Nullable;

import java.util.function.BiFunction;

public class ChestRearAttachment extends BaseChestRearAttachment implements Inventory, NamedScreenHandlerFactory {
private DefaultedList<ItemStack> inventory;

public ChestRearAttachment(RearAttachmentType<?> type, AutomobileEntity entity, BlockState block, @Nullable BiFunction<ScreenHandlerContext, BlockRearAttachment, NamedScreenHandlerFactory> screenProvider) {
super(type, entity, block, screenProvider);
this.inventory = DefaultedList.ofSize(27, ItemStack.EMPTY);
}

@Override
public void onRemoved() {
super.onRemoved();

var pos = this.pos();
this.inventory.forEach(s -> ItemScatterer.spawn(this.world(), pos.x, pos.y, pos.z, s));
}

@Override
public int size() {
return this.inventory.size();
}

@Override
public boolean isEmpty() {
return this.inventory.stream().allMatch(ItemStack::isEmpty);
}

@Override
public ItemStack getStack(int slot) {
return this.inventory.get(slot);
}

@Override
public ItemStack removeStack(int slot, int amount) {
return Inventories.splitStack(this.inventory, slot, amount);
}

@Override
public ItemStack removeStack(int slot) {
return Inventories.removeStack(this.inventory, slot);
}

@Override
public void setStack(int slot, ItemStack stack) {
this.inventory.set(slot, stack);
}

@Override
public void markDirty() {
this.automobile.markDirty();
}

@Override
public boolean canPlayerUse(PlayerEntity player) {
return true;
}

@Override
public Text getDisplayName() {
return BaseChestRearAttachment.TITLE_CHEST;
}

@Nullable
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) {
return GenericContainerScreenHandler.createGeneric9x3(syncId, inv, this);
}

@Override
public void clear() {
this.inventory.clear();
}

@Override
public void onOpen(PlayerEntity player) {
this.open(player);
}

@Override
public void onClose(PlayerEntity player) {
this.close(player);
}

@Override
protected SoundEvent getOpenSound() {
return SoundEvents.BLOCK_CHEST_OPEN;
}

@Override
protected SoundEvent getCloseSound() {
return SoundEvents.BLOCK_CHEST_CLOSE;
}

@Override
public void writeNbt(NbtCompound nbt) {
super.writeNbt(nbt);

nbt.put("Items", Inventories.writeNbt(new NbtCompound(), this.inventory));
}

@Override
public void readNbt(NbtCompound nbt) {
super.readNbt(nbt);

Inventories.readNbt(nbt.getCompound("Items"), this.inventory);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.foundationgames.automobility.automobile.render.attachment.rear;

import io.github.foundationgames.automobility.Automobility;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.model.EntityModelLayer;

public class ChestRearAttachmentModel extends RearAttachmentRenderModel {
public static final EntityModelLayer MODEL_LAYER = new EntityModelLayer(Automobility.id("automobile/rear_attachment/chest"), "main");

public ChestRearAttachmentModel(EntityRendererFactory.Context ctx) {
super(RenderLayer::getEntityCutoutNoCull, ctx, MODEL_LAYER);
}
}
Loading

0 comments on commit 15754c8

Please sign in to comment.