Skip to content

Commit

Permalink
Merge pull request #832 from ScicraftLearn/main
Browse files Browse the repository at this point in the history
UPdate version on the site
  • Loading branch information
BertJorissen authored Nov 21, 2023
2 parents 7ff38eb + e80c899 commit 4008012
Show file tree
Hide file tree
Showing 28 changed files with 575 additions and 301 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.21
# Mod Properties
mod_version=1.0.0
mod_version=1.0.2
maven_group=be.uantwerpen
mod_id=minelabs
archives_base_name=minelabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public class ChargedPointScreen extends HandledScreen<ChargedPointScreenHandler>

public ChargedPointScreen(ChargedPointScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);
}

@Override
protected void init() {
super.init();
playerInventoryTitleY -= 15;
}

Expand Down
45 changes: 20 additions & 25 deletions src/client/java/be/minelabs/client/gui/screen/IonicScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,29 @@
@Environment(EnvType.CLIENT)
public class IonicScreen extends HandledScreen<IonicBlockScreenHandler> implements ScreenHandlerProvider<IonicBlockScreenHandler> {

private static final Identifier TEXTURE = new Identifier(Minelabs.MOD_ID,"textures/block/ioniccrafting/ionic_gui.png");
private static final Identifier TEXTURE = new Identifier(Minelabs.MOD_ID, "textures/block/ioniccrafting/ionic_gui.png");

//just the height and width of the texture
public IonicScreen(IonicBlockScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);
backgroundHeight = 200;
backgroundWidth =206;
}

@Override
protected void init() {
super.init();
backgroundWidth = 206;
playerInventoryTitleX = 22;
playerInventoryTitleY= 105;
playerInventoryTitleY = 105;
}

@Override
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
RenderSystem.setShaderColor(1.0f,1.0f,1.0f,1.0f);
RenderSystem.setShaderTexture(0,TEXTURE);
int x = (width - backgroundWidth) /2;
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
RenderSystem.setShaderTexture(0, TEXTURE);
int x = (width - backgroundWidth) / 2;
int y = (height - backgroundHeight) / 2;
drawTexture(matrices, x, y, 0, 0, backgroundWidth,backgroundHeight);
drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight);

// Keep mapping between stack (in graph) and slots (for rendering)
Map<ItemStack, Slot> stackToSlotMap = new HashMap<>();
for (int i = 0; i < IonicBlockScreenHandler.GRIDSIZE*2; i++) {
for (int i = 0; i < IonicBlockScreenHandler.GRIDSIZE * 2; i++) {
stackToSlotMap.put(handler.getInventory().getStack(i), handler.getSlot(i));
}

Expand Down Expand Up @@ -88,15 +83,15 @@ protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int
DefaultedList<Ingredient> leftIngredients = handler.getLeftIngredients();
for (int i = 0; i < leftIngredients.size(); i++) {
ItemStack atom = leftIngredients.get(i).getMatchingStacks()[0];
if(this.handler.getLeftDensity() == 0 || atom.isEmpty()) {
if (this.handler.getLeftDensity() == 0 || atom.isEmpty()) {
break;
}
if (handler.getInventory().getStack(2*IonicBlockScreenHandler.GRIDSIZE+i).getCount() < handler.getLeftDensity()) {
this.itemRenderer.renderInGuiWithOverrides(matrices, new ItemStack(Items.RED_STAINED_GLASS_PANE), x + 12 + 18*i, 86+y);
if (handler.getInventory().getStack(2 * IonicBlockScreenHandler.GRIDSIZE + i).getCount() < handler.getLeftDensity()) {
this.itemRenderer.renderInGuiWithOverrides(matrices, new ItemStack(Items.RED_STAINED_GLASS_PANE), x + 12 + 18 * i, 86 + y);
} else {
this.itemRenderer.renderInGuiWithOverrides(matrices, new ItemStack(Items.GREEN_STAINED_GLASS_PANE), x + 12 + 18*i, 86+y);
this.itemRenderer.renderInGuiWithOverrides(matrices, new ItemStack(Items.GREEN_STAINED_GLASS_PANE), x + 12 + 18 * i, 86 + y);
}
this.itemRenderer.renderInGuiWithOverrides(matrices, atom, x + 12 + 18*i, 86+y);
this.itemRenderer.renderInGuiWithOverrides(matrices, atom, x + 12 + 18 * i, 86 + y);
}

/*
Expand All @@ -105,19 +100,19 @@ protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int
DefaultedList<Ingredient> rightIngredients = handler.getRightIngredients();
for (int i = 0; i < rightIngredients.size(); i++) {
ItemStack atom = rightIngredients.get(i).getMatchingStacks()[0];
if(this.handler.getRightDensity() == 0 || atom.isEmpty()) {
if (this.handler.getRightDensity() == 0 || atom.isEmpty()) {
break;
}
if (handler.getInventory().getStack(2*IonicBlockScreenHandler.GRIDSIZE + i + leftIngredients.size()).getCount() < handler.getRightDensity()) {
this.itemRenderer.renderInGuiWithOverrides(matrices, new ItemStack(Items.RED_STAINED_GLASS_PANE), x + 12 + 18*i + 18*leftIngredients.size(), 86+y);
if (handler.getInventory().getStack(2 * IonicBlockScreenHandler.GRIDSIZE + i + leftIngredients.size()).getCount() < handler.getRightDensity()) {
this.itemRenderer.renderInGuiWithOverrides(matrices, new ItemStack(Items.RED_STAINED_GLASS_PANE), x + 12 + 18 * i + 18 * leftIngredients.size(), 86 + y);
} else {
this.itemRenderer.renderInGuiWithOverrides(matrices, new ItemStack(Items.GREEN_STAINED_GLASS_PANE), x + 12 + 18*i + 18*leftIngredients.size(), 86+y);
this.itemRenderer.renderInGuiWithOverrides(matrices, new ItemStack(Items.GREEN_STAINED_GLASS_PANE), x + 12 + 18 * i + 18 * leftIngredients.size(), 86 + y);
}
this.itemRenderer.renderInGuiWithOverrides(matrices, atom, x + 12 + 18*i + 18*leftIngredients.size(), 86+y);
this.itemRenderer.renderInGuiWithOverrides(matrices, atom, x + 12 + 18 * i + 18 * leftIngredients.size(), 86 + y);
}
if (handler.getLeftCharge() != 0 && handler.getRightCharge() != 0) {
this.textRenderer.draw(matrices,"+" + handler.getLeftCharge(), 66+x,6+y, 0);
this.textRenderer.draw(matrices,"-" + handler.getRightCharge(), 139+x,6+y, 0);
this.textRenderer.draw(matrices, "+" + handler.getLeftCharge(), 66 + x, 6 + y, 0);
this.textRenderer.draw(matrices, "-" + handler.getRightCharge(), 139 + x, 6 + y, 0);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public class LabChestScreen extends HandledScreen<LabChestScreenHandler> {

public LabChestScreen(LabChestScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);
}

@Override
protected void init() {
super.init();
titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
Expand All @@ -26,11 +25,9 @@
import net.minecraft.recipe.Ingredient;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -46,6 +43,8 @@ public LewisScreen(LewisBlockScreenHandler handler, PlayerInventory inventory, T
super(handler, inventory, title);
// 3x18 for 3 inventory slots | +4 for extra offset to match the double chest | +5 for the row between the 5x5 grid and the input slots
backgroundHeight += (18 * 3 + 4) + 5;
// move the title to the correct place
playerInventoryTitleY += 61;
}

/*
Expand Down Expand Up @@ -153,9 +152,6 @@ protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int
protected void init() {
super.init();

// move the title to the correct place
playerInventoryTitleY += 61;

registerButtonWidget();
}

Expand Down
12 changes: 12 additions & 0 deletions src/client/java/be/minelabs/client/mixin/ItemRendererAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package be.minelabs.client.mixin;

import net.minecraft.client.render.item.ItemModels;
import net.minecraft.client.render.item.ItemRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(ItemRenderer.class)
public interface ItemRendererAccessor {
@Accessor("models")
ItemModels getModels();
}
30 changes: 30 additions & 0 deletions src/client/java/be/minelabs/client/mixin/ItemRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package be.minelabs.client.mixin;

import be.minelabs.Minelabs;
import be.minelabs.item.Items;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(ItemRenderer.class)
public abstract class ItemRendererMixin {
@ModifyVariable(method = "renderItem", at = @At(value = "HEAD"), argsOnly = true)
public BakedModel useBalloonModel(BakedModel value, ItemStack stack, ModelTransformationMode renderMode,
boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers,
int light, int overlay) {

// Do not render the balloon in 3D if it is in the GUI, on the ground, or in an item frame/armor stand
boolean bl = renderMode == ModelTransformationMode.GUI || renderMode == ModelTransformationMode.GROUND || renderMode == ModelTransformationMode.FIXED;
if (stack.isOf(Items.BALLOON) && !bl) {
return ((ItemRendererAccessor) this).getModels().getModelManager().getModel(new ModelIdentifier(Minelabs.MOD_ID, "balloon_3d", "inventory"));
}
return value;
}
}
28 changes: 28 additions & 0 deletions src/client/java/be/minelabs/client/mixin/ModelLoaderMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package be.minelabs.client.mixin;

import be.minelabs.Minelabs;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.json.JsonUnbakedModel;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;
import java.util.Map;

@Mixin(ModelLoader.class)
public abstract class ModelLoaderMixin {
@Shadow
protected abstract void addModel(ModelIdentifier modelId);

@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelLoader;addModel(Lnet/minecraft/client/util/ModelIdentifier;)V", ordinal = 3, shift = At.Shift.AFTER))
public void addBalloon(BlockColors blockColors, Profiler profiler, Map<Identifier, JsonUnbakedModel> jsonUnbakedModels, Map<Identifier, List<ModelLoader.SourceTrackedData>> blockStates, CallbackInfo ci) {
this.addModel(new ModelIdentifier(Minelabs.MOD_ID, "balloon_3d", "inventory"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,20 @@
import be.minelabs.entity.mob.BalloonEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.RotationAxis;
import org.joml.Quaternionf;

@Environment(EnvType.CLIENT)
public class BalloonEntityRenderer extends MobEntityRenderer<BalloonEntity, BalloonEntityModel> {

private static final Identifier TEXTURE = new Identifier(Minelabs.MOD_ID, "textures/entity/balloon/balloon.png");

public BalloonEntityRenderer(EntityRendererFactory.Context context) {
super(context, new BalloonEntityModel(context.getPart(EntityModelLayers.BALLOON_MODEL)), 0.7F);
}

@Override
public Identifier getTexture(BalloonEntity entity) {
return new Identifier(Minelabs.MOD_ID, "textures/entity/balloon/balloon.png");
}

@Override
public void render(BalloonEntity mobEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
Quaternionf rot = RotationAxis.POSITIVE_Y.rotationDegrees(mobEntity.getRotationY());
matrixStack.multiply(rot);
super.render(mobEntity, f, g, matrixStack, vertexConsumerProvider, i);
return TEXTURE;
}
}
5 changes: 4 additions & 1 deletion src/client/resources/minelabs.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"package": "be.minelabs.client.mixin",
"compatibilityLevel": "JAVA_17",
"client": [
"LabCoatArmorItemMixin"
"ItemRendererAccessor",
"ItemRendererMixin",
"LabCoatArmorItemMixin",
"ModelLoaderMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/be/minelabs/block/ExtraDispenserBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

import be.minelabs.entity.projectile.thrown.ParticleEntity;
import be.minelabs.item.Items;
import be.minelabs.item.items.BalloonItem;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.ItemDispenserBehavior;
import net.minecraft.block.dispenser.ProjectileDispenserBehavior;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Position;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.util.math.*;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;

import java.util.List;

public class ExtraDispenserBehavior {
/**
* Main class method
Expand Down Expand Up @@ -61,6 +63,23 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
return stack;
}
});

DispenserBlock.registerBehavior(Items.BALLOON, new ItemDispenserBehavior() {
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
if(stack.getItem() instanceof BalloonItem bi) {
BlockPos blockPos = pointer.getPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
List<LivingEntity> list = pointer.getWorld().getEntitiesByClass(LivingEntity.class, new Box(blockPos), EntityPredicates.EXCEPT_SPECTATOR);
if (list.isEmpty()) {
return super.dispenseSilently(pointer, stack);
} else {
LivingEntity livingEntity = list.get(0);
bi.useOnEntity(stack, null, livingEntity, null);
return stack;
}
}
return super.dispenseSilently(pointer, stack);
}
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/be/minelabs/entity/Entities.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Entities {
.dimensions(EntityDimensions.fixed(0.6f, 1.7f)).build(), "entropy_creeper");

public static final EntityType<BalloonEntity> BALLOON = register(FabricEntityTypeBuilder.create(SpawnGroup.MISC, BalloonEntity::new)
.dimensions(EntityDimensions.fixed(1.0f, 1.0f)).build(), "balloon");
.dimensions(EntityDimensions.fixed(0.8f, 1.0f)).disableSummon().build(), "balloon");
public static final EntityType<CorrosiveEntity> CORROSIVE_ENTITY = register(FabricEntityTypeBuilder.create(SpawnGroup.MISC, CorrosiveEntity::new)
.dimensions(EntityDimensions.fixed(1.0f, 1.0f)).disableSummon().fireImmune().build(), "corrosive");

Expand Down
Loading

0 comments on commit 4008012

Please sign in to comment.