-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add models for grindstone and stonecutter, add chest and ender chest …
…attachments, add launch gel
- Loading branch information
1 parent
cc14d3c
commit 15754c8
Showing
32 changed files
with
2,874 additions
and
25 deletions.
There are no files selected for viewing
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
100 changes: 100 additions & 0 deletions
100
...thub/foundationgames/automobility/automobile/attachment/rear/BaseChestRearAttachment.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,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) | ||
); | ||
} | ||
} |
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
130 changes: 130 additions & 0 deletions
130
...o/github/foundationgames/automobility/automobile/attachment/rear/ChestRearAttachment.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,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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ndationgames/automobility/automobile/render/attachment/rear/ChestRearAttachmentModel.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,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); | ||
} | ||
} |
Oops, something went wrong.