Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Started update to 1.20. #194

Open
wants to merge 1 commit into
base: 1.20
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Common/src/main/java/com/terraformersmc/campanion/Campanion.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.terraformersmc.campanion.network.S2CEntitySpawnGrapplingHookPacket;
import com.terraformersmc.campanion.network.S2CSyncBackpackContents;
import com.terraformersmc.campanion.platform.Services;
import com.terraformersmc.campanion.stat.CampanionStats;
import com.terraformersmc.campanion.tag.CampanionBlockTags;
import com.terraformersmc.campanion.tag.CampanionItemTags;
import net.minecraft.Util;
Expand All @@ -24,6 +23,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DispenserBlock;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -35,7 +35,7 @@ public class Campanion {

public static CreativeModeTab TAB;

public static void init() {
public static void init() {
TAB = Services.PLATFORM.createItemGroup("items", () -> CampanionItems.SMORE.asItem().getDefaultInstance());


Expand All @@ -47,12 +47,12 @@ public static void init() {

CampanionBlockTags.load();
CampanionItemTags.load();
}
}

public static void registerDispenserBehavior() {
DispenserBlock.registerBehavior(CampanionItems.SKIPPING_STONE, new AbstractProjectileDispenseBehavior() {
@Override
protected Projectile getProjectile(Level world, Position position, ItemStack stack) {
protected @NotNull Projectile getProjectile(@NotNull Level world, @NotNull Position position, @NotNull ItemStack stack) {
return Util.make(new SkippingStoneEntity(world, position.x(), position.y(), position.z()), (snowballEntity) -> {
snowballEntity.setItem(stack);
});
Expand All @@ -61,7 +61,7 @@ protected Projectile getProjectile(Level world, Position position, ItemStack sta

DispenserBlock.registerBehavior(CampanionItems.FLARE, new AbstractProjectileDispenseBehavior() {
@Override
protected Projectile getProjectile(Level world, Position position, ItemStack stack) {
protected @NotNull Projectile getProjectile(@NotNull Level world, @NotNull Position position, @NotNull ItemStack stack) {
return Util.make(new FlareEntity(world, position.x(), position.y(), position.z()), (flareEntity) -> {
flareEntity.setItem(stack);
});
Expand All @@ -70,8 +70,6 @@ protected Projectile getProjectile(Level world, Position position, ItemStack sta

}



public static void registerPackets() {
Services.NETWORK.registerServerBound(C2SOpenBackpack.class, C2SOpenBackpack::new, C2SOpenBackpack::handle);
Services.NETWORK.registerServerBound(C2SRotateHeldItem.class, C2SRotateHeldItem::new, C2SRotateHeldItem::handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.ThrownItemRenderer;
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.terraformersmc.campanion.advancement.criterion;

import com.google.gson.JsonObject;
import net.minecraft.advancements.critereon.AbstractCriterionTriggerInstance;
import net.minecraft.advancements.critereon.DeserializationContext;
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.advancements.critereon.SerializationContext;
import net.minecraft.advancements.critereon.SimpleCriterionTrigger;
import net.minecraft.advancements.critereon.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.NotNull;

public class CountCriterion extends SimpleCriterionTrigger<CountCriterion.Conditions> {
public final ResourceLocation id;
Expand All @@ -18,7 +14,7 @@ public CountCriterion(ResourceLocation id) {
}

@Override
public ResourceLocation getId() {
public @NotNull ResourceLocation getId() {
return id;
}

Expand All @@ -27,29 +23,29 @@ public void trigger(ServerPlayer player, int count) {
}

@Override
protected Conditions createInstance(JsonObject json, EntityPredicate.Composite entityPredicate, DeserializationContext deserializer) {
protected @NotNull Conditions createInstance(JsonObject json, @NotNull ContextAwarePredicate predicate, @NotNull DeserializationContext deserializer) {
MinMaxBounds.Ints count = MinMaxBounds.Ints.fromJson(json.get("count"));
return new CountCriterion.Conditions(id, count, entityPredicate);
return new CountCriterion.Conditions(id, count, predicate);
}

public static class Conditions extends AbstractCriterionTriggerInstance {
private final MinMaxBounds.Ints count;

public Conditions(ResourceLocation id, MinMaxBounds.Ints count, EntityPredicate.Composite entityPredicate) {
public Conditions(ResourceLocation id, MinMaxBounds.Ints count, ContextAwarePredicate entityPredicate) {
super(id, entityPredicate);
this.count = count;
}

public static CountCriterion.Conditions create(ResourceLocation id, MinMaxBounds.Ints count, EntityPredicate.Composite entityPredicate) {
return new CountCriterion.Conditions(id, count, entityPredicate);
public static CountCriterion.Conditions create(ResourceLocation id, MinMaxBounds.Ints count, ContextAwarePredicate predicate) {
return new CountCriterion.Conditions(id, count, predicate);
}

public boolean matches(int count) {
return this.count.matches(count);
}

@Override
public JsonObject serializeToJson(SerializationContext serializer) {
public @NotNull JsonObject serializeToJson(@NotNull SerializationContext serializer) {
JsonObject json = new JsonObject();
json.add("count", this.count.serializeToJson());
return json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@

import com.google.gson.JsonObject;
import com.terraformersmc.campanion.Campanion;
import net.minecraft.advancements.critereon.AbstractCriterionTriggerInstance;
import net.minecraft.advancements.critereon.DeserializationContext;
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.advancements.critereon.SerializationContext;
import net.minecraft.advancements.critereon.SimpleCriterionTrigger;
import net.minecraft.advancements.critereon.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.NotNull;

public class KilledWithStoneCriterion extends SimpleCriterionTrigger<KilledWithStoneCriterion.Conditions> {
public static final ResourceLocation ID = new ResourceLocation(Campanion.MOD_ID, "killed_with_stone");

@Override
public ResourceLocation getId() {
public @NotNull ResourceLocation getId() {
return ID;
}

Expand All @@ -25,30 +21,30 @@ public void trigger(ServerPlayer player, Entity entity, int count) {
}

@Override
protected Conditions createInstance(JsonObject json, EntityPredicate.Composite entityPredicate, DeserializationContext deserializer) {
return new KilledWithStoneCriterion.Conditions(EntityPredicate.fromJson(json.get("entity")), MinMaxBounds.Ints.fromJson(json.get("skips")), entityPredicate);
protected @NotNull Conditions createInstance(JsonObject json, @NotNull ContextAwarePredicate predicate, @NotNull DeserializationContext deserializer) {
return new KilledWithStoneCriterion.Conditions(EntityPredicate.fromJson(json.get("entity")), MinMaxBounds.Ints.fromJson(json.get("skips")), predicate);
}

public static class Conditions extends AbstractCriterionTriggerInstance {
private final EntityPredicate entity;
private final MinMaxBounds.Ints skips;

public Conditions(EntityPredicate entity, MinMaxBounds.Ints skips, EntityPredicate.Composite entityPredicate) {
super(KilledWithStoneCriterion.ID, entityPredicate);
public Conditions(EntityPredicate entity, MinMaxBounds.Ints skips, ContextAwarePredicate predicate) {
super(KilledWithStoneCriterion.ID, predicate);
this.entity = entity;
this.skips = skips;
}

public static KilledWithStoneCriterion.Conditions create(EntityPredicate entity, MinMaxBounds.Ints count, EntityPredicate.Composite entityPredicate) {
return new KilledWithStoneCriterion.Conditions(entity, count, entityPredicate);
public static KilledWithStoneCriterion.Conditions create(EntityPredicate entity, MinMaxBounds.Ints count, ContextAwarePredicate predicate) {
return new KilledWithStoneCriterion.Conditions(entity, count, predicate);
}

public boolean matches(ServerPlayer player, Entity entity, int count) {
return this.skips.matches(count) && this.entity.matches(player, entity);
}

@Override
public JsonObject serializeToJson(SerializationContext serializer) {
public @NotNull JsonObject serializeToJson(@NotNull SerializationContext serializer) {
JsonObject json = new JsonObject();
json.add("entity", this.entity.serializeToJson());
json.add("skips", this.skips.serializeToJson());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class BackpackContainerFactory implements MenuProvider {
Expand All @@ -21,12 +22,12 @@ public BackpackContainerFactory(BackpackItem.Type type) {
}

@Override
public Component getDisplayName() {
public @NotNull Component getDisplayName() {
return Component.translatable("container.campanion." + this.type.name().toLowerCase());
}

@Override
public @Nullable AbstractContainerMenu createMenu(int syncId, Inventory inv, Player player) {
public @Nullable AbstractContainerMenu createMenu(int syncId, @NotNull Inventory inv, @NotNull Player player) {
BackpackStorePlayer storePlayer = (BackpackStorePlayer) player;
NonNullList<ItemStack> stacks = storePlayer.getBackpackStacks();
SimpleContainer inventory = new SimpleContainer(this.type.getSlots());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static int getStackCapacity(ItemStack stack) {

default void syncChanges() {
Player player = (Player) this;
if(!player.level.isClientSide) {
if (!player.level().isClientSide) {
Services.NETWORK.sendToPlayer(new S2CSyncBackpackContents(this.getBackpackStacks()), (ServerPlayer) player);
}
}
Expand All @@ -34,7 +34,7 @@ default void changeBackpackCapacity(int newCapacity) {
NonNullList<ItemStack> stacks = this.getBackpackStacks();

while (stacks.size() > newCapacity) {
Containers.dropItemStack(player.level, pos.getX(), pos.getY()+eyeHeight, pos.getZ(), stacks.remove(newCapacity));
Containers.dropItemStack(player.level(), pos.getX(), pos.getY() + eyeHeight, pos.getZ(), stacks.remove(newCapacity));
}

syncChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

public abstract class BaseTent4WayBlock extends BaseTentBlock {

protected static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

private final VoxelShape northShape;
Expand All @@ -43,19 +43,14 @@ public BlockState getStateForPlacement(BlockPlaceContext ctx) {
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext context) {
switch (state.getValue(FACING)) {
case NORTH:
return this.northShape;
case EAST:
return this.eastShape;
case SOUTH:
return this.southShape;
case WEST:
return this.westShape;
default:
return super.getShape(state, view, pos, context);
}
public @NotNull VoxelShape getShape(BlockState state, @NotNull BlockGetter view, @NotNull BlockPos pos, @NotNull CollisionContext context) {
return switch (state.getValue(FACING)) {
case NORTH -> this.northShape;
case EAST -> this.eastShape;
case SOUTH -> this.southShape;
case WEST -> this.westShape;
default -> super.getShape(state, view, pos, context);
};
}

@Override
Expand All @@ -64,12 +59,12 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
}

@Override
public BlockState rotate(BlockState state, Rotation rotation) {
public @NotNull BlockState rotate(BlockState state, Rotation rotation) {
return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
}

@Override
public BlockState mirror(BlockState state, Mirror mirror) {
public @NotNull BlockState mirror(BlockState state, Mirror mirror) {
return state.rotate(mirror.getRotation(state.getValue(FACING)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.terraformersmc.campanion.blockentity.TentPartBlockEntity;
import com.terraformersmc.campanion.item.CampanionItems;
import com.terraformersmc.campanion.item.TentBagItem;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -29,6 +27,10 @@
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

public class BaseTentBlock extends Block implements EntityBlock {

Expand All @@ -45,12 +47,12 @@ public BaseTentBlock(Properties settings, DyeColor color) {
}

@Override
public boolean propagatesSkylightDown(BlockState state, BlockGetter view, BlockPos pos) {
public boolean propagatesSkylightDown(@NotNull BlockState state, @NotNull BlockGetter view, @NotNull BlockPos pos) {
return true;
}

@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
public @NotNull InteractionResult use(@NotNull BlockState state, Level world, @NotNull BlockPos pos, Player player, @NotNull InteractionHand hand, @NotNull BlockHitResult hit) {
BlockEntity blockEntity = world.getBlockEntity(pos);
ItemStack stack = player.getItemInHand(hand);
if (!world.isClientSide && stack.getItem() instanceof DyeItem && blockEntity instanceof TentPartBlockEntity && this.color != null) {
Expand Down Expand Up @@ -79,15 +81,15 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
}

@Override
public void onRemove(BlockState state, Level world, BlockPos pos, BlockState newState, boolean moved) {
public void onRemove(BlockState state, @NotNull Level world, @NotNull BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock().getClass() == newState.getBlock().getClass()) {
return;
}
super.onRemove(state, world, pos, newState, moved);
}

@Override
public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Player player) {
public void playerWillDestroy(@NotNull Level world, @NotNull BlockPos pos, @NotNull BlockState state, Player player) {
int slotIndex = -1;
for (int i = 0; i < player.getInventory().getContainerSize(); i++) {
ItemStack stack = player.getInventory().getItem(i);
Expand Down Expand Up @@ -135,7 +137,7 @@ public void playerWillDestroy(Level world, BlockPos pos, BlockState state, Playe


@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
return new TentPartBlockEntity(pos, state);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

import java.util.Random;

Expand All @@ -24,32 +25,32 @@ public FlareBlock(Properties settings) {
}

@Override
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
public void onPlace(@NotNull BlockState state, Level world, @NotNull BlockPos pos, @NotNull BlockState oldState, boolean notify) {
world.scheduleTick(pos, this, new Random().nextInt(150) + 100);
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
public @NotNull VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter world, @NotNull BlockPos pos, @NotNull CollisionContext context) {
return Block.box(4, 0, 4, 12, 4, 12);
}

public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
public @NotNull BlockState updateShape(@NotNull BlockState state, @NotNull Direction direction, @NotNull BlockState newState, @NotNull LevelAccessor world, @NotNull BlockPos pos, @NotNull BlockPos posFrom) {
return direction == Direction.DOWN && !this.canSurvive(state, world, pos) ? Blocks.AIR.defaultBlockState() : super.updateShape(state, direction, newState, world, pos, posFrom);
}

public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
public boolean canSurvive(@NotNull BlockState state, @NotNull LevelReader world, BlockPos pos) {
return canSupportCenter(world, pos.below(), Direction.UP);
}

public void animateTick(BlockState state, Level world, BlockPos pos, Random random) {
double d = (double)pos.getX() + 0.5D;
double e = (double)pos.getY() + 0.2D;
double f = (double)pos.getZ() + 0.5D;
double d = (double) pos.getX() + 0.5D;
double e = (double) pos.getY() + 0.2D;
double f = (double) pos.getZ() + 0.5D;
world.addParticle(ParticleTypes.LAVA, d, e, f, 0.0D, 0.0D, 0.0D);
}

@Override
public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) {
public void tick(@NotNull BlockState state, ServerLevel world, @NotNull BlockPos pos, @NotNull RandomSource random) {
world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
}
}
Loading
Loading